From ab934e6c54fc6fb03ce5e855945d21d6ee3b009a 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 | 3 ++- 1 file changed, 2 insertions(+), 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 6597163faa8..cd3d6f09581 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 @@ -620,9 +620,10 @@ public static CallSite contextValueString(Lookup lookup, String name, MethodType .from(Ruby.class, ThreadContext.class, MutableCallSite.class) .invokeStaticQuiet(LOOKUP, Bootstrap.class, "runtime"); + // We use LOOKUP here to have a full-featured MethodHandles.Lookup, avoiding jruby/jruby#7911 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 =