Skip to content

Commit 8a820d4

Browse files
committed
Fix: NPE
1 parent 3ef9293 commit 8a820d4

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/main/java/com/c0d3p1ut0s/StackTraceTransformer.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,27 @@ public ClassAdapter(final ClassVisitor cv, String className) {
4040
public MethodVisitor visitMethod(final int access, final String name,
4141
final String desc, final String signature, final String[] exceptions) {
4242
MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
43+
if (clazzName != null) {
44+
final String methodName = clazzName.replace('/', '.') + "." + name;
45+
for (String methodPrefix : StackTraceHelper.methodPrefix) {
46+
if (methodName.startsWith(methodPrefix)) {
47+
MethodVisitor nmv = new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
48+
@Override
49+
protected void onMethodEnter() {
50+
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
51+
mv.visitLdcInsn("Enter Method: " + methodName);
52+
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
4353

44-
final String methodName = clazzName.replace('/', '.') + "." + name;
45-
for (String methodPrefix : StackTraceHelper.methodPrefix) {
46-
if (methodName.startsWith(methodPrefix)) {
47-
MethodVisitor nmv = new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
48-
@Override
49-
protected void onMethodEnter() {
50-
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
51-
mv.visitLdcInsn("Enter Method: " + methodName);
52-
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
53-
54-
mv.visitTypeInsn(NEW, "java/lang/Exception");
55-
mv.visitInsn(DUP);
56-
mv.visitLdcInsn("Java Stack Trace");
57-
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Exception", "<init>", "(Ljava/lang/String;)V", false);
58-
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
59-
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "(Ljava/io/PrintStream;)V", false);
60-
}
61-
};
62-
return nmv;
54+
mv.visitTypeInsn(NEW, "java/lang/Exception");
55+
mv.visitInsn(DUP);
56+
mv.visitLdcInsn("Java Stack Trace");
57+
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Exception", "<init>", "(Ljava/lang/String;)V", false);
58+
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
59+
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "(Ljava/io/PrintStream;)V", false);
60+
}
61+
};
62+
return nmv;
63+
}
6364
}
6465
}
6566
return mv;

0 commit comments

Comments
 (0)