Do not require full type reflection when listing methods/fields
Prior to this commit, the `RuntimeHintsAgent` and its testing infrastructure would assume that calling `MyClass.class.getMethods()` requires a reflection hint on the class for introspecting public/private methods. GraalVM does not require this, in fact this call only returns methods that have reflection hints in the native image. This commit refines the agent behavior for `Class.getMethods()`, `Class.getDeclaredMethods()`, `Class.getFields()` and `Class.getDeclaredFields()`. With this change, registering at least one method/field for reflection is enough to match. During the execution of Java tests, all methods and fields will be provided, regardless of hints being registered or not. This could cause false negatives where we're missing reflection hints on methods or fields. This risk is mitigated thanks to additional instrumentation on `Method.getAnnotations()`, `Method.getParameterTypes()` and `Method.invoke()`. If a method is found reflectively, chances are it will be used for further reflection. Closes gh-29091
This commit is contained in:
@@ -164,6 +164,22 @@ public class RuntimeHintsAgentTests {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, MethodReference.of(Method.class, "invoke")),
|
||||
Arguments.of((Runnable) () -> {
|
||||
try {
|
||||
toStringMethod.getAnnotations();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, MethodReference.of(Method.class, "getAnnotations")),
|
||||
Arguments.of((Runnable) () -> {
|
||||
try {
|
||||
toStringMethod.getParameterTypes();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, MethodReference.of(Method.class, "getParameterTypes")),
|
||||
Arguments.of((Runnable) () -> {
|
||||
try {
|
||||
privateGreetMethod.invoke(new PrivateClass());
|
||||
|
||||
Reference in New Issue
Block a user