Skip to content

Commit

Permalink
catch exception when method cant be make accessible (#17984)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-dukhno committed Dec 23, 2020
1 parent 7a02d13 commit 20167a2
Showing 1 changed file with 6 additions and 2 deletions.
Expand Up @@ -68,8 +68,12 @@ public static long readLongAttribute(String attributeName, long defaultValue) {
OperatingSystemMXBean systemMXBean = OPERATING_SYSTEM_MX_BEAN;
Method method = systemMXBean.getClass().getMethod(methodName);

// the method is public in Java 9
method.setAccessible(true);
try {
// the method is public in Java 9
method.setAccessible(true);
} catch (Exception e) {
return defaultValue;
}

Object value = method.invoke(systemMXBean);
if (value == null) {
Expand Down

0 comments on commit 20167a2

Please sign in to comment.