1 5 package com.tctest; 6 7 import java.io.ObjectStreamField ; 8 import java.util.ArrayList ; 9 import java.util.List ; 10 11 14 public class ClassAdapterTestTarget { 15 private static final String C = ClassAdapterTestTarget.class 16 .getName() 17 + "."; 18 19 public static final String KEY = C + "key"; 20 public static final String CSTR_THROW_EXCEPTION = C + "cstr-throw-exception"; 21 public static final String CSTR_AUTOLOCK_NO_EXCEPTION = C + "cstr-autolock-noexception"; 22 public static final String CSTR_AUTOLOCK_THROW_EXCEPTION_INSIDE = C 23 + "cstr-autolock-throw-exception-inside"; 24 25 private static final long serialVersionUID = 42L; 27 28 private static final ObjectStreamField [] serialPersistentFields = { new java.io.ObjectStreamField ( 30 "foo", 31 char[].class) }; 32 33 List myRoot = new ArrayList (); 34 35 public ClassAdapterTestTarget() { 36 String s = System.getProperty(KEY); 37 38 if (s != null) { 39 if (CSTR_THROW_EXCEPTION.equals(s)) { throw new RuntimeException (s); } 40 41 synchronized (s) { 44 if (CSTR_AUTOLOCK_THROW_EXCEPTION_INSIDE.equals(s)) { throw new RuntimeException (s); } 45 46 if (!CSTR_AUTOLOCK_NO_EXCEPTION.equals(s)) { throw new AssertionError (s); } 47 48 if (hashCode() != hashCode()) { return; } 49 } 50 } 51 } 52 53 public void doStuff() { 54 myRoot.add(this); 55 } 56 57 public synchronized void synchronizedInstanceMethodWithWideArgs(double d, long l) { 58 System.out.println("You called synchronizedInstanceMethodWithWideArgs(double, long)!"); 59 } 60 61 64 public void instanceMethod() { 65 System.out.println("You called instanceMethod()!"); 66 } 67 68 public void instanceMethodThrowsException() throws LockTestThrowsExceptionException { 69 System.out.println("You called lockTestThrowsException()! About to throw an exception..."); 70 throw new LockTestThrowsExceptionException(); 71 } 72 73 public void instanceMethodWithArguments(int i) { 74 System.out.println("You called instanceMethodWithArguments(" + i + ")"); 75 } 76 77 public void instanceMethodWithArguments(int i, String s) { 78 System.out.println("You called instanceMethodWithArguments(" + i + ", " + s + ")"); 79 } 80 81 public void instanceMethodWithArgumentsThrowsException(int i, String s) throws LockTestThrowsExceptionException { 82 System.out.println("You called instanceMethodWithArgumentsThrowsException"); 83 throwException(); 84 } 85 86 public synchronized void synchronizedInstanceMethod() { 87 System.out.println("You called synchronizedInstanceMethod()"); 88 } 89 90 public synchronized void synchronizedInstanceMethodThrowsException() throws LockTestThrowsExceptionException { 91 System.out.println("You called synchronizedInstanceMethodThrowsException()! About to throw an exception..."); 92 throw new LockTestThrowsExceptionException(); 93 } 94 95 public synchronized void synchronizedInstanceMethodWithArguments(int i, String s) { 96 System.out.println("You called synchronizedInstanceMethodWithArguments"); 97 } 98 99 public synchronized void synchronizedInstanceMethodWithArgumentsThrowsException(int i, String s) 100 throws LockTestThrowsExceptionException { 101 System.out.println("You called synchronizedInstanceMethodWithArgumentsThrowsException(int, String)"); 102 throwException(); 103 } 104 105 public void internalSynchronizedInstanceMethod() { 106 synchronized (this) { 107 System.out.println("You called synchronizedInstanceMethod()!"); 108 } 109 } 110 111 public void internalSynchronizedInstanceMethodThrowsException() throws LockTestThrowsExceptionException { 112 synchronized (this) { 113 System.out.println("You called internalSynchronizedInstanceMethodThrowsException"); 114 throwException(); 115 } 116 } 117 118 public void internalSynchronizedInstanceMethodWithArguments(int i, String s) { 119 synchronized (this) { 120 System.out.println("You called internalSynchronizedInstanceMethodWithArguments(int, String)"); 121 } 122 } 123 124 public void internalSynchronizedInstanceMethodWithArgumentsThrowsException(int i, String s) 125 throws LockTestThrowsExceptionException { 126 synchronized (this) { 127 System.out.println("You called internalSynchronizedInstanceMethodWithArgumentsThrowsException(int, String)"); 128 throwException(); 129 } 130 } 131 132 public static void staticMethod() { 133 System.out.println("You called staticMethod()!"); 134 } 135 136 public static void staticMethodThrowsException() throws Exception { 137 throwException(); 138 } 139 140 public static void staticMethodWithArguments(int i, String s) { 141 System.out.println("You called staticMethodWithArguments(" + i + ", " + s + ")"); 142 } 143 144 public static void staticMethodWithArgumentsThrowsException(int i, String s) throws Exception { 145 System.out.println("You called staticMethodWithArgumentsThrowsException(" + i + ", " + s + ")"); 146 if (System.currentTimeMillis() > 0) { throw new LockTestThrowsExceptionException(); } 147 } 148 149 public static synchronized void synchronizedStaticMethod() { 150 System.out.println("You called synchronizedStaticMethod()"); 151 } 152 153 public static synchronized void synchronizedStaticMethodThrowsException() throws LockTestThrowsExceptionException { 154 System.out.println("You called synchronizedStaticMethodThrowsException()"); 155 throwException(); 156 } 157 158 public static synchronized void synchronizedStaticMethodWithArguments(int i, String s) { 159 System.out.println("You called synchronizedStaticMethodWithArguments"); 160 } 161 162 public static synchronized void synchronizedStaticMethodWithArgumentsThrowsException(int i, String s) 163 throws LockTestThrowsExceptionException { 164 System.out.println("You called synchronizedStaticMethodWithArgumentsThrowsException(int, String)"); 165 throwException(); 166 } 167 168 public static void internalSynchronizedStaticMethod() { 169 Object o = new Object (); 170 System.out.println("internalSynchronizedStaticMethod(): About to synchronized on " + o + "..."); 171 synchronized (o) { 172 System.out.println("You called internalSynchronizedStaticMethod()"); 173 } 174 } 175 176 public static void internalSynchronizedStaticMethodThrowsException() throws LockTestThrowsExceptionException { 177 Object o = new Object (); 178 synchronized (o) { 179 System.out.println("You called internalSynchronizedStaticMethodThrowsException()"); 180 throwException(); 181 } 182 } 183 184 public static void internalSynchronizedStaticMethodWithArguments(int i, String s) { 185 Object o = new Object (); 186 synchronized (o) { 187 System.out.println("You called internalSynchronizedStaticMethodWithArguments(int, String)"); 188 } 189 } 190 191 public static void internalSynchronizedStaticMethodWithArgumentsThrowsException(int i, String s) 192 throws LockTestThrowsExceptionException { 193 Object o = new Object (); 194 synchronized (o) { 195 System.out.println("You called internalSynchronizedStaticMethodWithArgumentsThrowsException(int, String)"); 196 throwException(); 197 } 198 } 199 200 public String instanceMethodReturnsAValue() { 201 String rv = "some return value"; 202 System.out.println("You called instanceMethodReturnsAValue(). Returning: " + rv); 203 return rv; 204 } 205 206 public String instanceMethodReturnsAValueThrowsException() throws LockTestThrowsExceptionException { 207 String rv = "You called instanceMethodReturnsAValueThrowsException()"; 208 System.out.println(rv); 209 throwException(); 210 return rv; 211 } 212 213 public String instanceMethodWithArgumentsReturnsAValue(int i, String s) { 214 String rv = "You called instanceMethodWithArgumentsReturnsAValue(int, String)"; 215 System.out.println(rv); 216 return rv; 217 } 218 219 public String instanceMethodWithArgumentsReturnsAValueThrowsException(int i, String s) 220 throws LockTestThrowsExceptionException { 221 String rv = "You called instanceMethodWithArgumentsReturnsAValueThrowsException(int, String)"; 222 System.out.println(rv); 223 throwException(); 224 return rv; 225 } 226 227 public synchronized String synchronizedInstanceMethodReturnsAValue() { 228 String rv = "some return value"; 229 System.out.println("You called synchronizedInstanceMethodReturnsAValue(). Returning " + rv); 230 return rv; 231 } 232 233 public synchronized String synchronizedInstanceMethodReturnsAValueThrowsException() 234 throws LockTestThrowsExceptionException { 235 String rv = "You called synchronizedInstanceMethodReturnsAValueThrowsException()"; 236 System.out.println(rv); 237 throwException(); 238 return rv; 239 } 240 241 public synchronized String synchronizedInstanceMethodWithArgumentsReturnsAValue(int i, String s) { 242 String rv = "You called synchronizedInstanceMethodWithArgumentsReturnsAValue(int, String)"; 243 System.out.println(rv); 244 return rv; 245 } 246 247 public synchronized String synchronizedInstanceMethodWithArgumentsReturnsAValueThrowsException(int i, String s) 248 throws LockTestThrowsExceptionException { 249 String rv = "You called synchronizedInstanceMethodWithArgumentsReturnsAValueThrowsException(int, String)"; 250 System.out.println("rv"); 251 throwException(); 252 return rv; 253 } 254 255 public String internalSynchronizedInstanceMethodReturnsAValue() { 256 String rv = "You called internalSynchronizedInstanceMethodReturnsAValue()"; 257 synchronized (this) { 258 System.out.println(rv); 259 } 260 return rv; 261 } 262 263 public String internalSynchronizedInstanceMethodReturnsAValueThrowsException() 264 throws LockTestThrowsExceptionException { 265 String rv = "You called internalSynchronizedInstanceMethodReturnsAValueThrowsException()"; 266 synchronized (this) { 267 System.out.println(rv); 268 throwException(); 269 } 270 return rv; 271 } 272 273 public String internalSynchronizedInstanceMethodWithArgumentsReturnsAValue(int i, String s) { 274 String rv = "You called internalSynchronizedInstanceMethodWithArgumentsReturnsAValue(int, String)"; 275 synchronized (this) { 276 System.out.println(rv); 277 } 278 return rv; 279 } 280 281 public String internalSynchronizedInstanceMethodWithArgumentsReturnsAValueThrowsException(int i, String s) 282 throws LockTestThrowsExceptionException { 283 String rv = "You called internalSynchronizedInstanceMethodWithArgumentsReturnsAValueThrowsException"; 284 synchronized (this) { 285 System.out.println(rv); 286 throwException(); 287 } 288 return rv; 289 } 290 291 public static String staticMethodReturnsAValue() { 292 String rv = "You called staticMethodReturnsAValue"; 293 System.out.println(rv); 294 return rv; 295 } 296 297 public static String staticMethodReturnsAValueThrowsException() throws Exception { 298 String rv = "You called staticMethodReturnsAValueThrowsException()"; 299 System.out.println(rv); 300 throwException(); 301 return rv; 302 } 303 304 public static String staticMethodWithArgumentsReturnsAValue(int i, String s) { 305 String rv = "You called staticMethodWithArgumentsReturnsAValue(int, String)"; 306 System.out.println(rv); 307 return rv; 308 } 309 310 public static String staticMethodWithArgumentsReturnsAValueThrowsException(int i, String s) throws Exception { 311 String rv = "You called staticMethodWithArgumentsReturnsAValueThrowsException(int, String)"; 312 throwException(); 313 return rv; 314 } 315 316 public static synchronized String synchronizedStaticMethodReturnsAValue() { 317 String rv = "You called synchronizedStaticMethodReturnsAValue()"; 318 System.out.println(rv); 319 return rv; 320 } 321 322 public static synchronized String synchronizedStaticMethodReturnsAValueThrowsException() 323 throws LockTestThrowsExceptionException { 324 String rv = "You called synchronizedStaticMethodReturnsAValueThrowsException()"; 325 System.out.println(rv); 326 throwException(); 327 return rv; 328 } 329 330 public static synchronized String synchronizedStaticMethodWithArgumentsReturnsAValue(int i, String s) { 331 String rv = "You called synchronizedStaticMethodWithArgumentsReturnsAValue(int, String)"; 332 System.out.println(rv); 333 return rv; 334 } 335 336 public static synchronized String synchronizedStaticMethodWithArgumentsReturnsAValueThrowsException(int i, String s) 337 throws LockTestThrowsExceptionException { 338 String rv = "You called synchronizedStaticMethodWithArgumentsReturnsAValueThrowsException(int i, String s)"; 339 System.out.println(rv); 340 throwException(); 341 return rv; 342 } 343 344 public static String internalSynchronizedStaticMethodReturnsAValue() { 345 String rv = "You called internalSynchronizedStaticMethodReturnsAValue()"; 346 Object o = new Object (); 347 synchronized (o) { 348 System.out.println(rv); 349 } 350 return rv; 351 } 352 353 public static String internalSynchronizedStaticMethodReturnsAValueThrowsException() 354 throws LockTestThrowsExceptionException { 355 String rv = "You called internalSynchronizedStaticMethodReturnsAValueThrowsException()"; 356 Object o = new Object (); 357 synchronized (o) { 358 System.out.println(rv); 359 throwException(); 360 } 361 return rv; 362 } 363 364 public static String internalSynchronizedStaticMethodWithArgumentsReturnsAValue(int i, String s) { 365 String rv = "You called internalSynchronizedStaticMethodWithArgumentsReturnsAValue(int, String)"; 366 Object o = new Object (); 367 synchronized (o) { 368 System.out.println(rv); 369 } 370 return rv; 371 } 372 373 public static String internalSynchronizedStaticMethodWithArgumentsReturnsAValueThrowsException(int i, String s) 374 throws LockTestThrowsExceptionException { 375 String rv = "You called internalSynchronizedStaticMethodWithArgumentsReturnsAValueThrowsException(int, String)"; 376 Object o = new Object (); 377 synchronized (o) { 378 System.out.println(rv); 379 throwException(); 380 } 381 return rv; 382 } 383 384 public int nestedInternalSynchronizedInstanceMethod() { 385 Object obj1 = new Object (); 386 Object obj2 = new Object (); 387 388 synchronized (obj1) { 389 System.out.println("Synchronized on obj1"); 390 synchronized (obj2) { 391 System.out.println("Synchronized on obj2"); 392 synchronized (this) { 393 System.out.println("Synchonized on this"); 394 return 3; 396 } 397 } 398 } 399 } 400 401 private static void throwException() throws LockTestThrowsExceptionException { 402 if (System.currentTimeMillis() > 0) { throw new LockTestThrowsExceptionException(); } 403 } 404 405 public static void main(String [] args) { 406 } 408 } | Popular Tags |