Enforce need for type reflection in RuntimeHintsAgent
Prior to this commit, the AOT infrastructure would rely on the fact that native runtime reflection on a type would only consider methods/fields/constructors that had specific hints contributed. When listing them through the reflection API on the type, the native image would only return those for which we had hints contributed. This behavior will soon change in GraalVM and will better align with the JVM behavior: when asking for all declared methods on a type in a native image, we should get all existing methods, not just the ones registered previously in the native image. This commit aligns the behavior of the `RuntimeHintsAgent` and removes the now misleading predicates as a consequence. Closes gh-29205
This commit is contained in:
@@ -243,29 +243,6 @@ public class ReflectionHintsPredicates {
|
||||
.anyMatch(memberCategory -> getTypeHint(hints).getMemberCategories().contains(memberCategory)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Refine the current predicate to only match if a hint is present for any of its constructors.
|
||||
* @return the refined {@link RuntimeHints} predicate
|
||||
*/
|
||||
public Predicate<RuntimeHints> withAnyConstructor() {
|
||||
return this.and(hints -> getTypeHint(hints).constructors().findAny().isPresent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Refine the current predicate to only match if a hint is present for any of its methods.
|
||||
* @return the refined {@link RuntimeHints} predicate
|
||||
*/
|
||||
public Predicate<RuntimeHints> withAnyMethod() {
|
||||
return this.and(hints -> getTypeHint(hints).methods().findAny().isPresent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Refine the current predicate to only match if a hint is present for any of its fields.
|
||||
* @return the refined {@link RuntimeHints} predicate
|
||||
*/
|
||||
public Predicate<RuntimeHints> withAnyField() {
|
||||
return this.and(hints -> getTypeHint(hints).fields().findAny().isPresent());
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class ExecutableHintPredicate<T extends Executable> implements Predicate<RuntimeHints> {
|
||||
|
||||
@@ -296,18 +296,6 @@ class ReflectionHintsPredicatesTests {
|
||||
assertPredicateMatches(reflection.onConstructor(privateConstructor).invoke());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reflectionOnAnyConstructorDoesNotMatchTypeReflection() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class);
|
||||
assertPredicateDoesNotMatch(reflection.onType(SampleClass.class).withAnyConstructor());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reflectionOnAnyConstructorMatchesConstructorReflection() {
|
||||
runtimeHints.reflection().registerConstructor(publicConstructor, ExecutableMode.INVOKE);
|
||||
assertPredicateMatches(reflection.onType(SampleClass.class).withAnyConstructor());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -457,18 +445,6 @@ class ReflectionHintsPredicatesTests {
|
||||
assertPredicateMatches(reflection.onMethod(SampleClass.class, "privateMethod").invoke());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reflectionOnAnyMethodDoesNotMatchTypeReflection() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class);
|
||||
assertPredicateDoesNotMatch(reflection.onType(SampleClass.class).withAnyMethod());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reflectionOnAnyMethodMatchesMethodReflection() {
|
||||
runtimeHints.reflection().registerMethod(publicMethod, ExecutableMode.INVOKE);
|
||||
assertPredicateMatches(reflection.onType(SampleClass.class).withAnyMethod());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -527,18 +503,6 @@ class ReflectionHintsPredicatesTests {
|
||||
assertPredicateMatches(reflection.onField(SampleClass.class, "privateField"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reflectionOnAnyFieldDoesNotMatchTypeReflection() {
|
||||
runtimeHints.reflection().registerType(SampleClass.class);
|
||||
assertPredicateDoesNotMatch(reflection.onType(SampleClass.class).withAnyField());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reflectionOnAnyFieldMatchesFieldReflection() {
|
||||
runtimeHints.reflection().registerField(publicField);
|
||||
assertPredicateMatches(reflection.onType(SampleClass.class).withAnyField());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void assertPredicateMatches(Predicate<RuntimeHints> predicate) {
|
||||
|
||||
Reference in New Issue
Block a user