arthas trace 命令输出的throw 行号没有对照物,缺少异常抛出点的类名和方法名

a7qyws3x  于 2022-04-21  发布在  Java
关注(0)|答案(0)|浏览(258)

环境信息

  • arthas-boot.jar 或者 as.sh 的版本: 3.3.7

问题描述

测试代码如下,替换MathGame对应的方法:

public List<Integer> primeFactors(int number) {
        if (number < 2) {
            illegalArgumentCount++;
            // throw from another class
            new ArrayList<Integer>().addAll(null);
        }

        List<Integer> result = new ArrayList<Integer>();
        int i = 2;
        while (i <= number) {
            if (number % i == 0) {
                result.add(i);
                number = number / i;
                i = 2;
            } else {
                i++;
            }
        }

        return result;
    }

trace命令:
trace *MathGame *

trace 结果:

`---ts=2020-07-21 15:17:09;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2
    `---[0.301281ms] demo.MathGame:run()
        `---[0.121846ms] demo.MathGame:primeFactors() #24 [throws Exception]
            `---[0.079205ms] demo.MathGame:primeFactors() [throws Exception]
                `---throw:java.lang.NullPointerException #581 [null]

从Trace 异常处理代码知道,throw的行号取的throwable最后一个方法的行号,throw 丢失了class method 信息,不方便理解。 #581 行为java.util.ArrayList#addAll(java.util.Collection<? extends E>) 方法的第一行c.toArray(),与MathGame.primeFactors()没办法对照起来:

// AbstractTraceAdviceListener

public void afterThrowing(ClassLoader loader, Class<?> clazz, ArthasMethod method, Object target, Object[] args,
                              Throwable throwable) throws Throwable {
        int lineNumber = throwable.getStackTrace()[0].getLineNumber();
        threadBoundEntity.get().view.begin("throw:" + throwable.getClass().getName() + "()" + " #" + lineNumber).end().end();
        final Advice advice = Advice.newForAfterThrowing(loader, clazz, method, target, args, throwable);
        finishing(advice);
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题