Fix RuntimeHintsPredicates matching rules

Prior to this commit, the `RuntimeHintsPredicates` would assume that
registering introspection or invocation hints for "all declared methods"
on a type would also include "all public methods". This is not true, as
the Java reflection API itself behaves differently.
`getDeclaredMethods()` does not return a superset of `getMethods()`, as
the latter can return inherited methods, but not the former.
Same reasoning applies to fields.

This commit fixes the hints predicates to only match if the correct hint
has been registered.

Fixes gh-31224
This commit is contained in:
Brian Clozel
2023-09-15 17:50:53 +02:00
parent 8f130316d2
commit 227049824c
3 changed files with 35 additions and 33 deletions

View File

@@ -408,15 +408,15 @@ class InstrumentedMethodTests {
}
@Test
void classGetMethodShouldMatchIntrospectDeclaredMethodsHint() {
void classGetMethodShouldNotMatchIntrospectDeclaredMethodsHint() {
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_METHODS);
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
}
@Test
void classGetMethodShouldMatchInvokeDeclaredMethodsHint() {
void classGetMethodShouldNotMatchInvokeDeclaredMethodsHint() {
hints.reflection().registerType(String.class, MemberCategory.INVOKE_DECLARED_METHODS);
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
}
@Test
@@ -544,9 +544,9 @@ class InstrumentedMethodTests {
}
@Test
void classGetFieldShouldMatchDeclaredFieldsHint() {
void classGetFieldShouldNotMatchDeclaredFieldsHint() {
hints.reflection().registerType(PublicField.class, MemberCategory.DECLARED_FIELDS);
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETFIELD, this.getPublicField);
assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETFIELD, this.getPublicField);
}
@Test