From bc7125b7b3e01179ba5cf8039b5df4ead32d7c17 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 6 Oct 2023 01:46:54 -0500 Subject: [PATCH] Use a lookup() for field access in static constant This field access appears to trigger a bug in Java 8 and 11 (at least) leading to linkage errors and classes leaking across classloaders when a method handle is resolved at static initialization time. See https://github.com/jruby/jruby/issues/7911 The change here provides a local MethodHandles.Lookup object rather than using a publicLookup() to acquire the field handle. This may work around whatever the JDK bug was. Fixes #7911 --- core/src/main/java/org/jruby/ir/targets/indy/Bootstrap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/jruby/ir/targets/indy/Bootstrap.java b/core/src/main/java/org/jruby/ir/targets/indy/Bootstrap.java index 6597163faa87..b4fb051241ec 100644 --- a/core/src/main/java/org/jruby/ir/targets/indy/Bootstrap.java +++ b/core/src/main/java/org/jruby/ir/targets/indy/Bootstrap.java @@ -622,7 +622,7 @@ public static CallSite contextValueString(Lookup lookup, String name, MethodType private static final MethodHandle RUNTIME_FROM_CONTEXT_HANDLE = Binder - .from(Ruby.class, ThreadContext.class) + .from(LOOKUP, Ruby.class, ThreadContext.class) .getFieldQuiet("runtime"); private static final MethodHandle NIL_HANDLE =