public void ma() org.aspectj.weaver.MethodDeclarationLineNumber: 14:307
:
- INVOKESTATIC Two.aspectOf ()LTwo;
+ INVOKESTATIC Two.aspectOf ()LTwo; (line 15)
INVOKEVIRTUAL Two.ajc$before$Two$1$8d8821ee ()V
ALOAD_0
DUP
ASTORE_1
MONITORENTER
finally -> E1
- | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 15)
+ | GETSTATIC java.lang.System.err Ljava/io/PrintStream;
| LDC "hello"
| INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V
| ALOAD_1
public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
//public void testGenericsProblem_pr151978() { runTest("generics problem");}
- //public void testMissingLineNumbersInStacktraceBefore_pr145442() { runTest("missing line numbers in stacktrace before");}
- //public void testMissingLineNumbersInStacktraceAfter_pr145442() { runTest("missing line numbers in stacktrace after");}
- //public void testMissingLineNumbersInStacktraceAround_pr145442() { runTest("missing line numbers in stacktrace around");}
+// public void testMissingLineNumbersInStacktraceAfter_pr145442() { runTest("missing line numbers in stacktrace after");}
+// public void testMissingLineNumbersInStacktraceAround_pr145442() { runTest("missing line numbers in stacktrace around");}
// public void testArgnamesAndJavac_pr148381() { runTest("argNames and javac");}
// public void testCFlowXMLAspectLTW_pr149096() { runTest("cflow xml concrete aspect"); }
// public void testAmbiguousBinding_pr121805() { runTest("ambiguous binding");}
// public void testNoIllegalStateExceptionWithGenericInnerAspect_pr156058() { runTest("no IllegalStateException with generic inner aspect"); }
// public void testNegatedAnnotationMatchingProblem_pr153464() { runTest("negated annotation matching problem");}
+ public void testMissingLineNumbersInStacktraceBefore_pr145442() { runTest("missing line numbers in stacktrace before");}
+ public void testMissingLineNumbersInStacktraceBefore_pr145442_Binary() { runTest("missing line numbers in stacktrace before - binary");}
public void testAnnotationStylePointcutNPE_pr158412() { runTest("annotation style pointcut npe"); }
public void testAnnotationStylePointcutNPE_pr158412_2() { runTest("annotation style pointcut npe - 2"); }
public void testAnnotationsCallConstructors_pr158126() { runTest("annotations, call and constructors problem");}
<compile files="hello/HelloWorld.java hello/ThrowExceptionBefore.aj"/>
<run class="hello.HelloWorld">
<stderr>
- <line text="hello.HelloWorld.println(HelloWorld.java:13)"/>
- <!--line text="hello.HelloWorld.println(HelloWorld.java)"/-->
+ <line text="hello.HelloWorld.println(HelloWorld.java:14)"/>
+ <line text="hello.HelloWorld.testStackTrace(HelloWorld.java:19)"/>
+ <line text="hello.HelloWorld.main(HelloWorld.java:41)"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs153/pr145442" title="missing line numbers in stacktrace before - binary">
+ <compile inpath="helloworld.jar" files="hello/ThrowExceptionBefore.aj"/>
+ <run class="hello.HelloWorld">
+ <stderr>
+ <line text="hello.HelloWorld.println(HelloWorld.java:14)"/>
<line text="hello.HelloWorld.testStackTrace(HelloWorld.java:19)"/>
<line text="hello.HelloWorld.main(HelloWorld.java:41)"/>
</stderr>
<compile files="hello/HelloWorld.java hello/ThrowExceptionAfter.aj"/>
<run class="hello.HelloWorld">
<stderr>
- <line text="hello.HelloWorld.println(HelloWorld.java:15)"/>
+ <line text="hello.HelloWorld.println(HelloWorld.java:14)"/>
<line text="hello.HelloWorld.testStackTrace(HelloWorld.java:19)"/>
<line text="hello.HelloWorld.main(HelloWorld.java:41)"/>
</stderr>
<compile files="hello/HelloWorld.java hello/ThrowExceptionAround.aj" options="-XnoInline"/>
<run class="hello.HelloWorld">
<stderr>
- <line text="hello.HelloWorld.println(HelloWorld.java:13)"/>
- <!--line text="hello.HelloWorld.println(HelloWorld.java:1)"/-->
+ <line text="hello.HelloWorld.println(HelloWorld.java:14)"/>
<line text="hello.HelloWorld.testStackTrace(HelloWorld.java:19)"/>
<line text="hello.HelloWorld.main(HelloWorld.java:41)"/>
</stderr>
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.LineNumberTag;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.Message;
import org.aspectj.weaver.Advice;
il.append(getNonTestAdviceInstructions(shadow));
InstructionHandle ifYesAdvice = il.getStart();
- il.insert(getTestInstructions(shadow, ifYesAdvice, ifNoAdvice, ifYesAdvice));
+ il.insert(getTestInstructions(shadow, ifYesAdvice, ifNoAdvice, ifYesAdvice));
+
+ // If inserting instructions at the start of a method, we need a nice line number for this entry
+ // in the stack trace
+ if (shadow.getKind()==Shadow.MethodExecution && getKind()==AdviceKind.Before) {
+ int lineNumber=0;
+ // Uncomment this code if you think we should use the method decl line number when it exists...
+// // If the advised join point is in a class built by AspectJ, we can use the declaration line number
+// boolean b = shadow.getEnclosingMethod().getMemberView().hasDeclarationLineNumberInfo();
+// if (b) {
+// lineNumber = shadow.getEnclosingMethod().getMemberView().getDeclarationLineNumber();
+// } else { // If it wasn't, the best we can do is the line number of the first instruction in the method
+ lineNumber = shadow.getEnclosingMethod().getMemberView().getLineNumberOfFirstInstruction();
+// }
+ if (lineNumber>0) il.getStart().addTargeter(new LineNumberTag(lineNumber));
+ }
+
+
return il;
}
import org.aspectj.apache.bcel.classfile.ExceptionTable;
import org.aspectj.apache.bcel.classfile.GenericSignatureParser;
import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.apache.bcel.classfile.LineNumber;
+import org.aspectj.apache.bcel.classfile.LineNumberTable;
import org.aspectj.apache.bcel.classfile.LocalVariable;
import org.aspectj.apache.bcel.classfile.LocalVariableTable;
import org.aspectj.apache.bcel.classfile.Method;
return super.getParameterNames();
}
+ public int getLineNumberOfFirstInstruction() {
+ LineNumberTable lnt = method.getLineNumberTable();
+ if (lnt==null) return -1;
+ LineNumber[] lns = lnt.getLineNumberTable();
+ if (lns==null || lns.length==0) return -1;
+ return lns[0].getLineNumber();
+ }
public void determineParameterNames() {
if (parameterNamesInitialized) return;
ALOAD_0
ASTORE 19
method-execution(void FancyHelloWorld.main(java.lang.String[]))
- | INVOKESTATIC Aspect.ajc_before_method_execution ()V
+ | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 9)
| BIPUSH 1
| ANEWARRAY java.lang.Object
| ASTORE 21
public static String getName():
method-execution(java.lang.String FancyHelloWorld.getName())
- | INVOKESTATIC Aspect.ajc_before_method_execution ()V
+ | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 20)
| BIPUSH 0
| ANEWARRAY java.lang.Object
| ASTORE 15
end static final void main_aroundBody20(String[])
static final void main_aroundBody22(String[]):
- INVOKESTATIC Aspect.ajc_before_method_execution ()V
+ INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 9)
BIPUSH 1
ANEWARRAY java.lang.Object
ASTORE_1
end static final String getName_aroundBody40()
static final String getName_aroundBody42():
- INVOKESTATIC Aspect.ajc_before_method_execution ()V
+ INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 20)
BIPUSH 0
ANEWARRAY java.lang.Object
ASTORE_0
ALOAD_0
ASTORE 7
method-execution(void HelloWorld.main(java.lang.String[]))
- | INVOKESTATIC Aspect.ajc_before_method_execution ()V
+ | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 8)
| BIPUSH 1
| ANEWARRAY java.lang.Object
| ASTORE 9
end static final void main_aroundBody12(String[])
static final void main_aroundBody14(String[]):
- INVOKESTATIC Aspect.ajc_before_method_execution ()V
+ INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 8)
BIPUSH 1
ANEWARRAY java.lang.Object
ASTORE_1
public static void main(String[]):
method-execution(void FancyHelloWorld.main(java.lang.String[]))
- | INVOKESTATIC Aspect.ajc_before_method_execution ()V
+ | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 9)
| field-get(java.io.PrintStream java.lang.System.out)
| | INVOKESTATIC Aspect.ajc_before_field_get ()V
- | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 9)
+ | | GETSTATIC java.lang.System.out Ljava/io/PrintStream;
| field-get(java.io.PrintStream java.lang.System.out)
| ASTORE_1
| finally -> E1
public static String getName():
method-execution(java.lang.String FancyHelloWorld.getName())
- | INVOKESTATIC Aspect.ajc_before_method_execution ()V
- | ICONST_0 (line 20)
+ | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 20)
+ | ICONST_0
| ISTORE_0
| ILOAD_0 // int x (line 21)
| LDC "name"
public static void main(String[]):
method-execution(void HelloWorld.main(java.lang.String[]))
- | INVOKESTATIC Aspect.ajc_before_method_execution ()V
+ | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 8)
| field-get(java.io.PrintStream java.lang.System.out)
| | INVOKESTATIC Aspect.ajc_before_field_get ()V
- | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 8)
+ | | GETSTATIC java.lang.System.out Ljava/io/PrintStream;
| field-get(java.io.PrintStream java.lang.System.out)
| LDC "hello world" (line 9)
| method-call(void java.io.PrintStream.println(java.lang.String))
public static void main(String[]):
method-execution(void DynamicHelloWorld.main(java.lang.String[]))
- | GETSTATIC Aspect.ajc$cflowStack$0 Lorg/aspectj/runtime/internal/CFlowStack;
+ | GETSTATIC Aspect.ajc$cflowStack$0 Lorg/aspectj/runtime/internal/CFlowStack; (line 12)
| INVOKEVIRTUAL org.aspectj.runtime.internal.CFlowStack.isValid ()Z
| IFEQ L0
| GETSTATIC Aspect.ajc$cflowStack$0 Lorg/aspectj/runtime/internal/CFlowStack;
| CHECKCAST java.util.ArrayList
| INVOKESTATIC Aspect.ajc_before_0 (Ljava/util/ArrayList;)V
| catch java.lang.UnsupportedOperationException -> E0
- | | L0: NEW DynamicHelloWorld (line 12)
+ | | L0: NEW DynamicHelloWorld
| | DUP
| | INVOKESPECIAL DynamicHelloWorld.<init> ()V
| | LDC "hello"
public static void main(String[]):
method-execution(void FieldyHelloWorld.main(java.lang.String[]))
- | INVOKESTATIC Aspect.ajc_before_method_execution ()V
+ | INVOKESTATIC Aspect.ajc_before_method_execution ()V (line 6)
| field-get(java.lang.String FieldyHelloWorld.str)
| | INVOKESTATIC Aspect.ajc_before_field_get ()V
- | | GETSTATIC FieldyHelloWorld.str Ljava/lang/String; (line 6)
+ | | GETSTATIC FieldyHelloWorld.str Ljava/lang/String;
| field-get(java.lang.String FieldyHelloWorld.str)
| method-call(java.lang.String java.lang.String.valueOf(java.lang.Object))
| | INVOKESTATIC Aspect.ajc_before_method_call ()V
public static void main(String[]):
method-execution(void HelloWorld.main(java.lang.String[]))
- | GETSTATIC HelloWorld.ajc$tjp_1 Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart;
+ | GETSTATIC HelloWorld.ajc$tjp_1 Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart; (line 8)
| INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint$StaticPart;)V
| field-get(java.io.PrintStream java.lang.System.out)
| | GETSTATIC HelloWorld.ajc$tjp_1 Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart;
| | INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint$StaticPart;)V
- | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 8)
+ | | GETSTATIC java.lang.System.out Ljava/io/PrintStream;
| field-get(java.io.PrintStream java.lang.System.out)
| LDC "hello world" (line 9)
| method-call(void java.io.PrintStream.println(java.lang.String))
public static void main(String[]):
method-execution(void HelloWorld.main(java.lang.String[]))
- | GETSTATIC HelloWorld.ajc$tjp_3 Lorg/aspectj/lang/JoinPoint$StaticPart;
+ | GETSTATIC HelloWorld.ajc$tjp_3 Lorg/aspectj/lang/JoinPoint$StaticPart; (line 8)
| INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint$StaticPart;)V
| field-get(java.io.PrintStream java.lang.System.out)
| | GETSTATIC HelloWorld.ajc$tjp_1 Lorg/aspectj/lang/JoinPoint$StaticPart;
| | INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint$StaticPart;)V
- | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 8)
+ | | GETSTATIC java.lang.System.out Ljava/io/PrintStream;
| field-get(java.io.PrintStream java.lang.System.out)
| LDC "hello world" (line 9)
| method-call(void java.io.PrintStream.println(java.lang.String))
INVOKESTATIC org.aspectj.runtime.reflect.Factory.makeJP (Lorg/aspectj/lang/JoinPoint$StaticPart;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lorg/aspectj/lang/JoinPoint;
ASTORE 5
method-execution(void HelloWorld.main(java.lang.String[]))
- | ALOAD 5
+ | ALOAD 5 (line 8)
| INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint;)V
| GETSTATIC HelloWorld.ajc$tjp_1 Lorg/aspectj/lang/JoinPoint$StaticPart;
| ACONST_NULL
| field-get(java.io.PrintStream java.lang.System.out)
| | ALOAD_1
| | INVOKESTATIC Aspect.ajc_before (Lorg/aspectj/lang/JoinPoint;)V
- | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 8)
+ | | GETSTATIC java.lang.System.out Ljava/io/PrintStream;
| field-get(java.io.PrintStream java.lang.System.out)
| LDC "hello world" (line 9)
| ASTORE_3
ALOAD_2
ASTORE 4
method-execution(java.lang.String DynamicHelloWorld.doit(java.lang.String, java.util.List))
- | INVOKESTATIC MyTrace.aspectOf ()LMyTrace;
+ | INVOKESTATIC MyTrace.aspectOf ()LMyTrace; (line 21)
| ALOAD_0
| INVOKEVIRTUAL Trace.ajc$before$Trace$1$26352be2 (Ljava/lang/Object;)V
| INVOKESTATIC MyTrace.aspectOf ()LMyTrace;