-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the agent not log stacktraces if introspected method not found
- Loading branch information
Showing
7 changed files
with
52 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
...agent-wildfly/src/main/java/uk/gov/justice/metrics/agent/wildfly/util/ReflectionUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
package uk.gov.justice.metrics.agent.wildfly.util; | ||
|
||
|
||
import static java.util.Optional.empty; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Optional; | ||
|
||
public class ReflectionUtil { | ||
public static Object invokeMethod(final Object obj, final String methodName, final Object... param) throws ReflectiveOperationException { | ||
public static Optional<Object> invokeMethod(final Object obj, final String methodName, final Object... param) throws ReflectiveOperationException { | ||
Class<?> clazz = obj.getClass(); | ||
for (int i = 0; i < 3; i++) { | ||
try { | ||
final Method method = param.length == 0 ? clazz.getDeclaredMethod(methodName) : clazz.getDeclaredMethod(methodName, param[0].getClass()); | ||
return method.invoke(obj, param); | ||
return Optional.ofNullable(method.invoke(obj, param)); | ||
} catch (IllegalAccessException | InvocationTargetException e) { | ||
throw e; | ||
} catch (NoSuchMethodException e) { | ||
final Class<?> superclass = clazz.getSuperclass(); | ||
if (superclass != null) { | ||
clazz = superclass; | ||
} else { | ||
throw e; | ||
return empty(); | ||
} | ||
} | ||
} | ||
return null; | ||
return empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters