Skip to content

Commit d7e41fa

Browse files
committed
handle exceptions from broken JMX connection
1 parent 654c5e5 commit d7e41fa

File tree

1 file changed

+40
-24
lines changed

1 file changed

+40
-24
lines changed

visualvm/jmx/src/org/graalvm/visualvm/jmx/impl/JmxSupport.java

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Properties getSystemProperties() {
113113
}
114114
return null;
115115
} catch (Exception e) {
116-
LOGGER.throwing(JmxSupport.class.getName(), "getSystemProperties", e); // NOI18N
116+
LOGGER.log(Level.INFO, "getSystemProperties", e); // NOI18N
117117
return null;
118118
}
119119
}
@@ -168,22 +168,27 @@ HotSpotDiagnosticMXBean getHotSpotDiagnostic() {
168168
}
169169

170170
String takeThreadDump(long[] threadIds) {
171-
ThreadMXBean threadMXBean = getThreadBean();
172-
if (threadMXBean == null) {
171+
try {
172+
ThreadMXBean threadMXBean = getThreadBean();
173+
if (threadMXBean == null) {
174+
return null;
175+
}
176+
ThreadInfo[] threads;
177+
StringBuilder sb = new StringBuilder(4096);
178+
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // NOI18N
179+
180+
if (hasDumpAllThreads()) {
181+
threads = threadMXBean.getThreadInfo(threadIds, true, true);
182+
} else {
183+
threads = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
184+
}
185+
sb.append(df.format(new Date()) + "\n"); // NOI18N
186+
printThreads(sb, threadMXBean, threads);
187+
return sb.toString();
188+
} catch (Exception e) {
189+
LOGGER.log(Level.INFO, "takeThreadDump[]", e); // NOI18N
173190
return null;
174191
}
175-
ThreadInfo[] threads;
176-
StringBuilder sb = new StringBuilder(4096);
177-
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // NOI18N
178-
179-
if (hasDumpAllThreads()) {
180-
threads = threadMXBean.getThreadInfo(threadIds, true, true);
181-
} else {
182-
threads = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
183-
}
184-
sb.append(df.format(new Date()) + "\n"); // NOI18N
185-
printThreads(sb, threadMXBean, threads);
186-
return sb.toString();
187192
}
188193

189194
String takeThreadDump() {
@@ -337,14 +342,19 @@ boolean takeHeapDump(String fileName) {
337342
}
338343

339344
String getFlagValue(String name) {
340-
HotSpotDiagnosticMXBean hsDiagnostic = getHotSpotDiagnostic();
341-
if (hsDiagnostic != null) {
342-
VMOption option = hsDiagnostic.getVMOption(name);
343-
if (option != null) {
344-
return option.getValue();
345+
try {
346+
HotSpotDiagnosticMXBean hsDiagnostic = getHotSpotDiagnostic();
347+
if (hsDiagnostic != null) {
348+
VMOption option = hsDiagnostic.getVMOption(name);
349+
if (option != null) {
350+
return option.getValue();
351+
}
345352
}
353+
return null;
354+
} catch (Exception ex) {
355+
LOGGER.log(Level.INFO,"getFlagValue", ex); // NOI18N
356+
return null;
346357
}
347-
return null;
348358
}
349359

350360
HeapHistogram takeHeapHistogram() {
@@ -373,15 +383,21 @@ HeapHistogram takeHeapHistogram() {
373383
Exceptions.printStackTrace(ex);
374384
} catch (ReflectionException ex) {
375385
Exceptions.printStackTrace(ex);
376-
}
386+
} catch (Exception ex) {
387+
LOGGER.log(Level.INFO,"takeHeapHistogram", ex); // NOI18N
388+
}
377389
}
378390
return null;
379391
}
380392

381393
void setFlagValue(String name, String value) {
394+
try {
382395
HotSpotDiagnosticMXBean hsDiagnostic = getHotSpotDiagnostic();
383-
if (hsDiagnostic != null) {
384-
hsDiagnostic.setVMOption(name,value);
396+
if (hsDiagnostic != null) {
397+
hsDiagnostic.setVMOption(name,value);
398+
}
399+
} catch (Exception ex) {
400+
LOGGER.log(Level.INFO,"setFlagValue", ex); // NOI18N
385401
}
386402
}
387403

0 commit comments

Comments
 (0)