Fixed getDefinedPackage lookup for OpenJ9 (8) (#9272)

This commit is contained in:
Jonas Kunz 2023-08-22 11:12:25 +02:00 committed by GitHub
parent 7d49bb1bbc
commit 3dbb965e94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 10 deletions

View File

@ -238,18 +238,16 @@ class InstrumentationModuleClassLoader extends ClassLoader {
MethodType methodType = MethodType.methodType(Package.class, String.class); MethodType methodType = MethodType.methodType(Package.class, String.class);
MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodHandles.Lookup lookup = MethodHandles.lookup();
try { try {
return lookup.findVirtual(ClassLoader.class, "getDefinedPackage", methodType);
} catch (NoSuchMethodException | IllegalAccessException e) {
// In Java 8 getDefinedPackage does not exist (HotSpot) or is not accessible (OpenJ9)
try { try {
return lookup.findVirtual(ClassLoader.class, "getDefinedPackage", methodType); return lookup.findVirtual(ClassLoader.class, "getPackage", methodType);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException ex) {
// Java 8 case throw new IllegalStateException("expected method to always exist!", ex);
try { } catch (IllegalAccessException ex2) {
return lookup.findVirtual(ClassLoader.class, "getPackage", methodType); throw new IllegalStateException("Method should be accessible from here", ex2);
} catch (NoSuchMethodException ex) {
throw new IllegalStateException("expected method to always exist!", ex);
}
} }
} catch (IllegalAccessException e) {
throw new IllegalStateException("Method should be accessible from here", e);
} }
} }
} }