From cfea6d18e5cb726de65f5bfbef09097aa0a6d469 Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Thu, 25 Jul 2024 14:51:44 +0800 Subject: [PATCH] fix thread command NullPointerException. #2875 --- .../arthas/core/command/monitor200/ThreadCommand.java | 6 ++++-- .../main/java/com/taobao/arthas/core/util/ThreadUtil.java | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadCommand.java index 2ef0db2383..df8fbf4fe1 100755 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadCommand.java @@ -212,8 +212,10 @@ private ExitStatus processTopBusyThreads(CommandProcess process) { List busyThreadInfos = new ArrayList(topNThreads.size()); for (ThreadVO thread : topNThreads) { ThreadInfo threadInfo = findThreadInfoById(threadInfos, thread.getId()); - BusyThreadInfo busyThread = new BusyThreadInfo(thread, threadInfo); - busyThreadInfos.add(busyThread); + if (threadInfo != null) { + BusyThreadInfo busyThread = new BusyThreadInfo(thread, threadInfo); + busyThreadInfos.add(busyThread); + } } process.appendResult(new ThreadModel(busyThreadInfos)); return ExitStatus.success(); diff --git a/core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java b/core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java index b709857cb7..945194ae84 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java +++ b/core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java @@ -266,6 +266,9 @@ public static String getFullStacktrace(ThreadInfo threadInfo, double cpuUsage, l } public static String getFullStacktrace(BusyThreadInfo threadInfo, int lockIdentityHashCode, int blockingThreadCount) { + if (threadInfo == null) { + return ""; + } StringBuilder sb = new StringBuilder("\"" + threadInfo.getName() + "\""); if (threadInfo.getId() > 0) { sb.append(" Id=").append(threadInfo.getId());