Fixed getDefinedPackage lookup for OpenJ9 (8) (#9272)
This commit is contained in:
parent
7d49bb1bbc
commit
3dbb965e94
|
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue