Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用wisp时,报NPE错误 #2875

Closed
1 task
Thomas-Kong opened this issue Jul 22, 2024 · 1 comment
Closed
1 task

使用wisp时,报NPE错误 #2875

Thomas-Kong opened this issue Jul 22, 2024 · 1 comment
Milestone

Comments

@Thomas-Kong
Copy link

Thomas-Kong commented Jul 22, 2024

环境信息

  • Arthas 版本: 3.7.2

重现问题的步骤

  1. thread -n 1

期望的结果

得到进程信息

实际运行的结果

Error during processing the command: java.lang.NullPointerException, message:null, please check $HOME/logs/arthas/arthas.log for more details.

把异常信息贴到这里
2024-07-22 15:03:08 [arthas-command-execute] ERROR c.t.a.c.s.system.impl.ProcessImpl -Error during processing the command:
java.lang.NullPointerException: null
	at com.taobao.arthas.core.util.ThreadUtil.getFullStacktrace(ThreadUtil.java:307)
	at com.taobao.arthas.core.command.view.ThreadView.draw(ThreadView.java:31)
	at com.taobao.arthas.core.command.view.ThreadView.draw(ThreadView.java:20)
	at com.taobao.arthas.core.distribution.impl.TermResultDistributorImpl.appendResult(TermResultDistributorImpl.java:28)
	at com.taobao.arthas.core.shell.system.impl.ProcessImpl.appendResult(ProcessImpl.java:268)
	at com.taobao.arthas.core.shell.system.impl.ProcessImpl.access$2100(ProcessImpl.java:38)
	at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessImpl.appendResult(ProcessImpl.java:620)
	at com.taobao.arthas.core.command.monitor200.ThreadCommand.processTopBusyThreads(ThreadCommand.java:218)
	at com.taobao.arthas.core.command.monitor200.ThreadCommand.process(ThreadCommand.java:122)
	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82)
	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)
	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)
	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)
	at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:385)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:855)
	at com.alibaba.wisp.engine.WispTask.runOutsideWisp(WispTask.java:299)
	at com.alibaba.wisp.engine.WispTask.runCommand(WispTask.java:274)
	at com.alibaba.wisp.engine.WispTask.access$100(WispTask.java:53)
	at com.alibaba.wisp.engine.WispTask$CacheableCoroutine.run(WispTask.java:241)
	at java.dyn.CoroutineBase.startInternal(CoroutineBase.java:62)

ThreadUtil.getFullStacktrace方法,没有对参数中的BusyThreadInfo中为null的信息做判断,导致NPE

public static String getFullStacktrace(BusyThreadInfo threadInfo, int lockIdentityHashCode, int blockingThreadCount) {
        StringBuilder sb = new StringBuilder("\"" + threadInfo.getName() + "\"");
        if (threadInfo.getId() > 0) {
            sb.append(" Id=").append(threadInfo.getId());
        } else {
            sb.append(" [Internal]");
        }
        double cpuUsage = threadInfo.getCpu();
        if (cpuUsage >= 0 && cpuUsage <= 100) {
            sb.append(" cpuUsage=").append(cpuUsage).append("%");
        }
        if (threadInfo.getDeltaTime() >= 0 ) {
            sb.append(" deltaTime=").append(threadInfo.getDeltaTime()).append("ms");
        }
        if (threadInfo.getTime() >= 0 ) {
            sb.append(" time=").append(threadInfo.getTime()).append("ms");
        }

        if (threadInfo.getState() == null) {
            sb.append("\n\n");
            return sb.toString();
        }

        sb.append(" ").append(threadInfo.getState());

        if (threadInfo.getLockName() != null) {
            sb.append(" on ").append(threadInfo.getLockName());
        }
        if (threadInfo.getLockOwnerName() != null) {
            sb.append(" owned by \"").append(threadInfo.getLockOwnerName()).append("\" Id=").append(threadInfo.getLockOwnerId());
        }
        if (threadInfo.isSuspended()) {
            sb.append(" (suspended)");
        }
        if (threadInfo.isInNative()) {
            sb.append(" (in native)");
        }
        sb.append('\n');
        int i = 0;
        for (; i < threadInfo.getStackTrace().length; i++) {
            StackTraceElement ste = threadInfo.getStackTrace()[i];
            sb.append("\tat ").append(ste.toString());
            sb.append('\n');
            if (i == 0 && threadInfo.getLockInfo() != null) {
                Thread.State ts = threadInfo.getState();
                switch (ts) {
                    case BLOCKED:
                        sb.append("\t-  blocked on ").append(threadInfo.getLockInfo());
                        sb.append('\n');
                        break;
                    case WAITING:
                        sb.append("\t-  waiting on ").append(threadInfo.getLockInfo());
                        sb.append('\n');
                        break;
                    case TIMED_WAITING:
                        sb.append("\t-  waiting on ").append(threadInfo.getLockInfo());
                        sb.append('\n');
                        break;
                    default:
                }
            }

            for (MonitorInfo mi : threadInfo.getLockedMonitors()) {
                if (mi.getLockedStackDepth() == i) {
                    sb.append("\t-  locked ").append(mi);
                    if (mi.getIdentityHashCode() == lockIdentityHashCode) {
                        Ansi highlighted = Ansi.ansi().fg(Ansi.Color.RED);
                        highlighted.a(" <---- but blocks ").a(blockingThreadCount).a(" other threads!");
                        sb.append(highlighted.reset().toString());
                    }
                    sb.append('\n');
                }
            }
        }
        if (i < threadInfo.getStackTrace().length) {
            sb.append("\t...");
            sb.append('\n');
        }

        LockInfo[] locks = threadInfo.getLockedSynchronizers();
        if (locks.length > 0) {
            sb.append("\n\tNumber of locked synchronizers = ").append(locks.length);
            sb.append('\n');
            for (LockInfo li : locks) {
                sb.append("\t- ").append(li);
                if (li.getIdentityHashCode() == lockIdentityHashCode) {
                    sb.append(" <---- but blocks ").append(blockingThreadCount);
                    sb.append(" other threads!");
                }
                sb.append('\n');
            }
        }
        sb.append('\n');
        return sb.toString().replace("\t", "    ");
    }
@hengyunabc
Copy link
Collaborator

欢迎提个pr上来~

@hengyunabc hengyunabc added this to the 4.0.0 milestone Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants