Skip to content

Commit

Permalink
Access RecordComponent via Class.forName. (#2465)
Browse files Browse the repository at this point in the history
This should mean that GraalVM will understand the reflective lookup of its methods.
See [documentation](https://www.graalvm.org/latest/reference-manual/native-image/dynamic-features/Reflection/#automatic-detection).
  • Loading branch information
eamonnmcmanus committed Aug 11, 2023
1 parent cdbbee4 commit c5c1fbf
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ReflectionHelper {
try {
// Try to construct the RecordSupportedHelper, if this fails, records are not supported on this JVM.
instance = new RecordSupportedHelper();
} catch (NoSuchMethodException e) {
} catch (ReflectiveOperationException e) {
instance = new RecordNotSupportedHelper();
}
RECORD_HELPER = instance;
Expand Down Expand Up @@ -215,11 +215,10 @@ private static class RecordSupportedHelper extends RecordHelper {
private final Method getName;
private final Method getType;

private RecordSupportedHelper() throws NoSuchMethodException {
private RecordSupportedHelper() throws NoSuchMethodException, ClassNotFoundException {
isRecord = Class.class.getMethod("isRecord");
getRecordComponents = Class.class.getMethod("getRecordComponents");
// Class java.lang.reflect.RecordComponent
Class<?> classRecordComponent = getRecordComponents.getReturnType().getComponentType();
Class<?> classRecordComponent = Class.forName("java.lang.reflect.RecordComponent");
getName = classRecordComponent.getMethod("getName");
getType = classRecordComponent.getMethod("getType");
}
Expand Down

0 comments on commit c5c1fbf

Please sign in to comment.