Skip to content

Commit 026c6f8

Browse files
committed
keep Runnable r strongly reachable so that it is not reclaimable by GC
The GC might occur before the second native library loading by another class loader, keep Runnable r strongly reachable so that it is not reclaimable by GC, and ensure UnsatisfiedLinkError. Signed-off-by: Jason Feng <[email protected]>
1 parent bf34de6 commit 026c6f8

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

test/jdk/java/lang/ClassLoader/nativeLibrary/NativeLibraryTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static void runTest() throws Exception {
9797
throw new RuntimeException("should fail to load the native library" +
9898
" by another class loader");
9999
} catch (UnsatisfiedLinkError e) {}
100+
// keep Runnable r strongly reachable so that it is not reclaimable by GC
101+
java.lang.ref.Reference.reachabilityFence(r);
100102
}
101103

102104
/*

0 commit comments

Comments
 (0)