环境信息
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);
}
暂无答案!
目前还没有任何答案,快来回答吧!