7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
+ |
import java.io.ByteArrayInputStream; |
11 |
+ |
import java.io.ByteArrayOutputStream; |
12 |
+ |
import java.io.ObjectInputStream; |
13 |
+ |
import java.io.ObjectOutputStream; |
14 |
|
import java.util.Arrays; |
15 |
|
import java.util.NoSuchElementException; |
16 |
|
import java.util.PropertyPermission; |
848 |
|
public Runnable awaiter(final CountDownLatch latch) { |
849 |
|
return new CheckedRunnable() { |
850 |
|
public void realRun() throws InterruptedException { |
851 |
< |
latch.await(); |
851 |
> |
await(latch); |
852 |
|
}}; |
853 |
|
} |
854 |
|
|
855 |
+ |
public void await(CountDownLatch latch) { |
856 |
+ |
try { |
857 |
+ |
assertTrue(latch.await(LONG_DELAY_MS, MILLISECONDS)); |
858 |
+ |
} catch (Throwable t) { |
859 |
+ |
threadUnexpectedException(t); |
860 |
+ |
} |
861 |
+ |
} |
862 |
+ |
|
863 |
|
public static class NPETask implements Callable<String> { |
864 |
|
public String call() { throw new NullPointerException(); } |
865 |
|
} |
1107 |
|
} |
1108 |
|
} |
1109 |
|
|
1110 |
+ |
@SuppressWarnings("unchecked") |
1111 |
+ |
public <T> T serialClone(T o) { |
1112 |
+ |
try { |
1113 |
+ |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1114 |
+ |
ObjectOutputStream oos = new ObjectOutputStream(bos); |
1115 |
+ |
oos.writeObject(o); |
1116 |
+ |
oos.flush(); |
1117 |
+ |
oos.close(); |
1118 |
+ |
ByteArrayInputStream bin = |
1119 |
+ |
new ByteArrayInputStream(bos.toByteArray()); |
1120 |
+ |
ObjectInputStream ois = new ObjectInputStream(bin); |
1121 |
+ |
return (T) ois.readObject(); |
1122 |
+ |
} catch (Throwable t) { |
1123 |
+ |
threadUnexpectedException(t); |
1124 |
+ |
return null; |
1125 |
+ |
} |
1126 |
+ |
} |
1127 |
|
} |