From 20167a209b2012d5b7f0ca1605f1363aab4130c4 Mon Sep 17 00:00:00 2001 From: Alex Dukhno <5074607+alex-dukhno@users.noreply.github.com> Date: Wed, 23 Dec 2020 14:11:14 +0200 Subject: [PATCH] catch exception when method cant be make accessible (#17984) --- .../com/hazelcast/util/OperatingSystemMXBeanSupport.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hazelcast/src/main/java/com/hazelcast/util/OperatingSystemMXBeanSupport.java b/hazelcast/src/main/java/com/hazelcast/util/OperatingSystemMXBeanSupport.java index 8d0c15e98aaa..09f9b572e637 100644 --- a/hazelcast/src/main/java/com/hazelcast/util/OperatingSystemMXBeanSupport.java +++ b/hazelcast/src/main/java/com/hazelcast/util/OperatingSystemMXBeanSupport.java @@ -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) {