On Wed, 27 Apr 2022 18:19:57 GMT, Kim Barrett <kbarr...@openjdk.org> wrote:
>> test/jdk/java/lang/ref/ReferenceClone.java line 52: >> >>> 50: } catch (CloneNotSupportedException e) { >>> 51: throw new RuntimeException("CloneableReference::clone >>> should not throw CloneNotSupportedException"); >>> 52: } >> >> Alternatively, it could simply let CNSE propagate. >> >> >> CloneableReference ref = new CloneableReference(o); >> ref.clone(); >> >> >> `test()` and `main` will need to declare this checked exception. > > That was my initial thought, but it doesn't work - CNSE is a checked > exception so must be handled. > test() and main will need to declare this checked exception. diff --git a/test/jdk/java/lang/ref/ReferenceClone.java b/test/jdk/java/lang/ref/ReferenceClone.java index bd1ead81bec..2f9386b81e4 100644 --- a/test/jdk/java/lang/ref/ReferenceClone.java +++ b/test/jdk/java/lang/ref/ReferenceClone.java @@ -31,12 +31,12 @@ import java.lang.ref.*; public class ReferenceClone { private static final ReferenceQueue<Object> QUEUE = new ReferenceQueue<>(); - public static void main(String... args) { + public static void main(String... args) throws Exception { ReferenceClone refClone = new ReferenceClone(); refClone.test(); } - public void test() { + public void test() throws CloneNotSupportedException { // test Reference::clone that throws CNSE Object o = new Object(); assertCloneNotSupported(new SoftRef(o)); @@ -45,9 +45,7 @@ public class ReferenceClone { // Reference subclass may override the clone method CloneableReference ref = new CloneableReference(o); - try { ref.clone(); - } catch (CloneNotSupportedException e) {} } private void assertCloneNotSupported(CloneableRef ref) { ``` ------------- PR: https://git.openjdk.java.net/jdk/pull/8418