From 8753c02ad1e5fd0a7d142c3128c05f4468a67ece Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Wed, 9 Dec 2020 11:32:10 +0800 Subject: [PATCH] fix NullPointerException in PidUtils. #1611 --- .../main/java/com/taobao/arthas/common/PidUtils.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/taobao/arthas/common/PidUtils.java b/common/src/main/java/com/taobao/arthas/common/PidUtils.java index 3dd74555a..41322e613 100644 --- a/common/src/main/java/com/taobao/arthas/common/PidUtils.java +++ b/common/src/main/java/com/taobao/arthas/common/PidUtils.java @@ -13,16 +13,16 @@ public class PidUtils { static { // https://stackoverflow.com/a/7690178 - String jvmName = ManagementFactory.getRuntimeMXBean().getName(); - int index = jvmName.indexOf('@'); + try { + String jvmName = ManagementFactory.getRuntimeMXBean().getName(); + int index = jvmName.indexOf('@'); - if (index > 0) { - try { + if (index > 0) { PID = Long.toString(Long.parseLong(jvmName.substring(0, index))); pid = Long.parseLong(PID); - } catch (Throwable e) { - // ignore } + } catch (Throwable e) { + // ignore } }