Skip to content

Commit c411260

Browse files
committed
[GR-66227] Register Object methods for reflective queries
PullRequest: graal/21161
2 parents 5e96a92 + fdd6b2d commit c411260

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,21 @@ public void registerAllClassesQuery(ConfigurationCondition condition, Class<?> c
226226
});
227227
}
228228

229+
void registerClassMetadata(ConfigurationCondition condition, Class<?> clazz) {
230+
registerAllDeclaredFieldsQuery(condition, true, clazz);
231+
registerAllFieldsQuery(condition, true, clazz);
232+
registerAllDeclaredMethodsQuery(condition, true, clazz);
233+
registerAllMethodsQuery(condition, true, clazz);
234+
registerAllDeclaredConstructorsQuery(condition, true, clazz);
235+
registerAllConstructorsQuery(condition, true, clazz);
236+
registerAllDeclaredClassesQuery(condition, clazz);
237+
registerAllClassesQuery(condition, clazz);
238+
registerAllRecordComponentsQuery(condition, clazz);
239+
registerAllPermittedSubclassesQuery(condition, clazz);
240+
registerAllNestMembersQuery(condition, clazz);
241+
registerAllSignersQuery(condition, clazz);
242+
}
243+
229244
/**
230245
* Runtime conditions can only be used with type, so they are not valid here.
231246
*/
@@ -1161,10 +1176,10 @@ public Map<Class<?>, Set<Class<?>>> getReflectionInnerClasses() {
11611176
public int getEnabledReflectionQueries(Class<?> clazz) {
11621177
int enabledQueries = enabledQueriesFlags.getOrDefault(clazz, 0);
11631178
/*
1164-
* Primitives, arrays and object are registered by default since they provide reflective
1165-
* access to either no members or only Object methods.
1179+
* Primitives and arrays are registered by default since they provide reflective access to
1180+
* no members.
11661181
*/
1167-
if (clazz == Object.class || clazz.isPrimitive() || clazz.isArray()) {
1182+
if (clazz.isPrimitive() || clazz.isArray()) {
11681183
enabledQueries |= ALL_DECLARED_CLASSES_FLAG | ALL_CLASSES_FLAG | ALL_DECLARED_CONSTRUCTORS_FLAG | ALL_CONSTRUCTORS_FLAG | ALL_DECLARED_METHODS_FLAG | ALL_METHODS_FLAG |
11691184
ALL_DECLARED_FIELDS_FLAG | ALL_FIELDS_FLAG;
11701185
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionFeature.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ public void afterRegistration(AfterRegistrationAccess access) {
295295
reflectionData = new ReflectionDataBuilder((SubstrateAnnotationExtractor) ImageSingletons.lookup(AnnotationExtractor.class));
296296
ImageSingletons.add(RuntimeReflectionSupport.class, reflectionData);
297297
ImageSingletons.add(ReflectionHostedSupport.class, reflectionData);
298+
299+
/*
300+
* Querying Object members is allowed to enable these accesses on array classes, since those
301+
* don't define any additional members.
302+
*/
303+
reflectionData.registerClassMetadata(ConfigurationCondition.alwaysTrue(), Object.class);
298304
}
299305

300306
@Override

0 commit comments

Comments
 (0)