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

Access RecordComponent via Class.forName. #2465

Merged
merged 1 commit into from
Aug 11, 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 @@ -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