Fix RuntimeHintsAgent instrumentation for method invocation

Prior to this commit, the `RuntimeHintsAgent` would instrument
`Method.invoke` in a way that fails when invoked methods are not public.

This commit ensures that before delegating the invocation call, the
instrumentation makes the method accessible before delegating the call.

Fixes gh-29046
This commit is contained in:
Brian Clozel
2022-08-31 15:19:31 +02:00
parent f877f81ae4
commit 3c22404bce
2 changed files with 38 additions and 2 deletions

View File

@@ -337,13 +337,21 @@ public abstract class InstrumentedBridgeMethods {
public static Object methodinvoke(Method method, Object object, Object... arguments) throws InvocationTargetException, IllegalAccessException {
Object result = null;
boolean accessibilityChanged = false;
try {
if (!Modifier.isPublic(method.getModifiers())) {
method.setAccessible(true);
accessibilityChanged = true;
}
result = method.invoke(object, arguments);
}
finally {
RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.METHOD_INVOKE)
.onInstance(method).withArguments(object, arguments).returnValue(result).build();
RecordedInvocationsPublisher.publish(invocation);
if (accessibilityChanged) {
method.setAccessible(false);
}
}
return result;
}