9 |
|
/* |
10 |
|
* @test |
11 |
|
* @summary JSR-166 tck tests |
12 |
< |
* @modules java.management |
12 |
> |
* @modules java.base/java.util.concurrent:open |
13 |
> |
* java.management |
14 |
|
* @build * |
15 |
|
* @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase |
16 |
|
* @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 -Djsr166.testImplementationDetails=true JSR166TestCase |
1829 |
|
} |
1830 |
|
} |
1831 |
|
|
1832 |
< |
void assertImmutable(Object o) { |
1832 |
> |
void assertImmutable(final Object o) { |
1833 |
|
if (o instanceof Collection) { |
1834 |
|
assertThrows( |
1835 |
|
UnsupportedOperationException.class, |
1854 |
|
} |
1855 |
|
|
1856 |
|
/** |
1857 |
+ |
* A version of serialClone that leaves error handling (for |
1858 |
+ |
* e.g. NotSerializableException) up to the caller. |
1859 |
+ |
*/ |
1860 |
+ |
@SuppressWarnings("unchecked") |
1861 |
+ |
<T> T serialClonePossiblyFailing(T o) |
1862 |
+ |
throws ReflectiveOperationException, java.io.IOException { |
1863 |
+ |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1864 |
+ |
ObjectOutputStream oos = new ObjectOutputStream(bos); |
1865 |
+ |
oos.writeObject(o); |
1866 |
+ |
oos.flush(); |
1867 |
+ |
oos.close(); |
1868 |
+ |
ObjectInputStream ois = new ObjectInputStream |
1869 |
+ |
(new ByteArrayInputStream(bos.toByteArray())); |
1870 |
+ |
T clone = (T) ois.readObject(); |
1871 |
+ |
if (o == clone) assertImmutable(o); |
1872 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1873 |
+ |
return clone; |
1874 |
+ |
} |
1875 |
+ |
|
1876 |
+ |
/** |
1877 |
|
* If o implements Cloneable and has a public clone method, |
1878 |
|
* returns a clone of o, else null. |
1879 |
|
*/ |