Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed getDefinedPackage lookup for OpenJ9 (8) #9272

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,16 @@ private static MethodHandle getFindPackageMethod() {
MethodType methodType = MethodType.methodType(Package.class, String.class);
MethodHandles.Lookup lookup = MethodHandles.lookup();
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 {
return lookup.findVirtual(ClassLoader.class, "getDefinedPackage", methodType);
} catch (NoSuchMethodException e) {
// Java 8 case
try {
return lookup.findVirtual(ClassLoader.class, "getPackage", methodType);
} catch (NoSuchMethodException ex) {
throw new IllegalStateException("expected method to always exist!", ex);
}
return lookup.findVirtual(ClassLoader.class, "getPackage", methodType);
} catch (NoSuchMethodException ex) {
throw new IllegalStateException("expected method to always exist!", ex);
} catch (IllegalAccessException ex2) {
throw new IllegalStateException("Method should be accessible from here", ex2);
}
} catch (IllegalAccessException e) {
throw new IllegalStateException("Method should be accessible from here", e);
}
}
}