print exception location

This commit is contained in:
金戟 2021-03-04 11:14:51 +08:00
parent 6f079db3f3
commit 5897e087c8
2 changed files with 20 additions and 6 deletions

View File

@ -41,7 +41,6 @@ public class TestableClassTransformer implements ClassFileTransformer {
/**
* Just avoid spend time to scan those surely non-user classes Should keep these lists as tiny as possible
*/
private final String[] WHITELIST_PREFIXES = new String[] {"com/alibaba/testable/demo/"};
private final String[] BLACKLIST_PREFIXES = new String[] {"jdk/", "java/", "javax/", "sun/", "com/sun/",
"org/apache/maven/", "com/alibaba/testable/", "junit/", "org/junit/", "org/testng/"};
@ -83,6 +82,7 @@ public class TestableClassTransformer implements ClassFileTransformer {
} catch (Throwable t) {
LogUtil.warn("Failed to transform class " + className);
LogUtil.diagnose(t.toString());
LogUtil.diagnose(ThreadUtil.getFirstRelatedStackLine(t));
} finally {
LogUtil.resetLogLevel();
}
@ -153,11 +153,6 @@ public class TestableClassTransformer implements ClassFileTransformer {
}
return true;
} else {
for (String prefix : WHITELIST_PREFIXES) {
if (className.startsWith(prefix)) {
return false;
}
}
for (String prefix : BLACKLIST_PREFIXES) {
if (className.startsWith(prefix)) {
return true;

View File

@ -0,0 +1,19 @@
package com.alibaba.testable.agent.util;
/**
* @author flin
*/
public class ThreadUtil {
private static final String PKG_TESTABLE_AGENT = "com.alibaba.testable.agent.";
public static String getFirstRelatedStackLine(Throwable t) {
for (StackTraceElement e : t.getStackTrace()) {
if (e.getClassName().startsWith(PKG_TESTABLE_AGENT)) {
return e.toString();
}
}
return "";
}
}