RFR: 8259267: Refactor LoaderLeak shell test as java test. [v9]

Daniel Fuchs dfuchs at openjdk.java.net
Mon Feb 22 17:03:48 UTC 2021


On Mon, 22 Feb 2021 15:50:03 GMT, Ivan Šipka <isipka at openjdk.org> wrote:

>> Refactor `test/jdk/java/lang/annotation/loaderLeak/LoaderLeak.sh` as java test.
>
> Ivan Šipka has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8166026: Refactor java/lang shell tests to java

test/jdk/java/lang/annotation/LoaderLeakTest.java line 77:

> 75:         var c = new WeakReference<Class<?>>(loader.loadClass("C"));
> 76:         if (c.get() == null) throw new AssertionError("class missing after loadClass");
> 77:         if (c.get().getClassLoader() != loader) throw new AssertionError("wrong classloader");

This can throw NPE as there is no guarantee that two subsequent calls will return the same value: c.get() could very well be null the second time around.

test/jdk/java/lang/annotation/LoaderLeakTest.java line 94:

> 92:             System.gc();
> 93:             Thread.sleep(20);
> 94:             if (c.get() == null) {

I'd suggest using the new `if (c.refersTo(null)) {` here.

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

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


More information about the core-libs-dev mailing list