Skip to content

[GR-66227] Register Object methods for reflective queries #11544

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

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
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 @@ -226,6 +226,21 @@ public void registerAllClassesQuery(ConfigurationCondition condition, Class<?> c
});
}

void registerClassMetadata(ConfigurationCondition condition, Class<?> clazz) {
registerAllDeclaredFieldsQuery(condition, true, clazz);
registerAllFieldsQuery(condition, true, clazz);
registerAllDeclaredMethodsQuery(condition, true, clazz);
registerAllMethodsQuery(condition, true, clazz);
registerAllDeclaredConstructorsQuery(condition, true, clazz);
registerAllConstructorsQuery(condition, true, clazz);
registerAllDeclaredClassesQuery(condition, clazz);
registerAllClassesQuery(condition, clazz);
registerAllRecordComponentsQuery(condition, clazz);
registerAllPermittedSubclassesQuery(condition, clazz);
registerAllNestMembersQuery(condition, clazz);
registerAllSignersQuery(condition, clazz);
}

/**
* Runtime conditions can only be used with type, so they are not valid here.
*/
Expand Down Expand Up @@ -1161,10 +1176,10 @@ public Map<Class<?>, Set<Class<?>>> getReflectionInnerClasses() {
public int getEnabledReflectionQueries(Class<?> clazz) {
int enabledQueries = enabledQueriesFlags.getOrDefault(clazz, 0);
/*
* Primitives, arrays and object are registered by default since they provide reflective
* access to either no members or only Object methods.
* Primitives and arrays are registered by default since they provide reflective access to
* no members.
*/
if (clazz == Object.class || clazz.isPrimitive() || clazz.isArray()) {
if (clazz.isPrimitive() || clazz.isArray()) {
enabledQueries |= ALL_DECLARED_CLASSES_FLAG | ALL_CLASSES_FLAG | ALL_DECLARED_CONSTRUCTORS_FLAG | ALL_CONSTRUCTORS_FLAG | ALL_DECLARED_METHODS_FLAG | ALL_METHODS_FLAG |
ALL_DECLARED_FIELDS_FLAG | ALL_FIELDS_FLAG;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ public void afterRegistration(AfterRegistrationAccess access) {
reflectionData = new ReflectionDataBuilder((SubstrateAnnotationExtractor) ImageSingletons.lookup(AnnotationExtractor.class));
ImageSingletons.add(RuntimeReflectionSupport.class, reflectionData);
ImageSingletons.add(ReflectionHostedSupport.class, reflectionData);

/*
* Querying Object members is allowed to enable these accesses on array classes, since those
* don't define any additional members.
*/
reflectionData.registerClassMetadata(ConfigurationCondition.alwaysTrue(), Object.class);
}

@Override
Expand Down
Loading