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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user