RFR: 8285690: CloneableReference subtest should not throw CloneNotSupportedException [v2]

Kim Barrett kbarrett at openjdk.java.net
Wed Apr 27 18:33:42 UTC 2022


On Wed, 27 Apr 2022 18:25:27 GMT, Mandy Chung <mchung at openjdk.org> wrote:

>> 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) {
>      ```

Yes, that would work.  But I'd rather keep the code for that subtest close together, i.e. as currently written.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8418


More information about the core-libs-dev mailing list