]> source.dussan.org Git - aspectj.git/commitdiff
test and fixes for 145442 - line number info for stack traces.
authoraclement <aclement>
Thu, 28 Sep 2006 10:51:13 +0000 (10:51 +0000)
committeraclement <aclement>
Thu, 28 Sep 2006 10:51:13 +0000 (10:51 +0000)
16 files changed:
tests/bugs153/pr145442/helloworld.jar [new file with mode: 0644]
tests/features152/synchronization/transformed/expected/C.ma.txt
tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java
tests/src/org/aspectj/systemtest/ajc153/ajc153.xml
weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java
weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
weaver/testdata/AroundAllAndOthersFancyHelloWorld.txt
weaver/testdata/AroundAllAndOthersHelloWorld.txt
weaver/testdata/BeforeFancyHelloWorld.txt
weaver/testdata/BeforeHelloWorld.txt
weaver/testdata/CflowStateResidueDynamicHelloWorld.txt
weaver/testdata/FieldSet.txt
weaver/testdata/StaticEnclosingTjpBeforeHelloWorld.txt
weaver/testdata/StaticTjpBeforeHelloWorld.txt
weaver/testdata/TjpBeforeHelloWorld.txt
weaver/testdata/TraceJarHello.txt

diff --git a/tests/bugs153/pr145442/helloworld.jar b/tests/bugs153/pr145442/helloworld.jar
new file mode 100644 (file)
index 0000000..17666f1
Binary files /dev/null and b/tests/bugs153/pr145442/helloworld.jar differ
index 0a6b97849bd00550d89014ea480ff87b164d0f5f..4d76af4e4998173f77b50a9498508ac78756d959 100644 (file)
@@ -1,13 +1,13 @@
   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
index bbe34a79f859bf7259b39b757a5f0764d8ef35d6..9e3da682953ea9cf012dcf2a10c86f8184ed39c1 100644 (file)
@@ -24,14 +24,15 @@ import org.aspectj.weaver.bcel.Utility;
 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");}
index 38654042b87627a22f74619625b1a5387c6fdcde..f65a256a309442bda11367fe3a6f64d90e6c11bc 100644 (file)
      <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>
index ab61031f6bf3357ec0037283d3544b3f52822ba2..2fcd25e6d44d51309eeb10fa71ccb9c2aec3e898 100644 (file)
@@ -24,6 +24,7 @@ import org.aspectj.apache.bcel.generic.InstructionConstants;
 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;
@@ -424,7 +425,24 @@ public class BcelAdvice extends 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;
        }
 
index 2bc6e97348a969e4319c44e403b79efd4e901701..13839f41a83d8963cccbccabbddd02500cc46cc6 100644 (file)
@@ -23,6 +23,8 @@ import org.aspectj.apache.bcel.classfile.Attribute;
 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;
@@ -102,6 +104,13 @@ public final class BcelMethod extends ResolvedMemberImpl {
                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;
index 789b9d37ecb80b652de231d9d42277b33a0255ba..dea1d2c638d9f18a3fe75b41b7646a5e6d323bac 100644 (file)
@@ -25,7 +25,7 @@ public abstract class FancyHelloWorld extends java.lang.Object:
                     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
@@ -45,7 +45,7 @@ public abstract class FancyHelloWorld extends java.lang.Object:
 
   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
@@ -292,7 +292,7 @@ public abstract class FancyHelloWorld extends java.lang.Object:
   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
@@ -500,7 +500,7 @@ public abstract class FancyHelloWorld extends java.lang.Object:
   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
index 2175e03c62caaa157b2d99e081a72992d37a5a00..b3d0b28fbe507de1f6da3f4a9e280a26cdd42ea9 100644 (file)
@@ -25,7 +25,7 @@ public class HelloWorld extends java.lang.Object:
                     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
@@ -153,7 +153,7 @@ public class HelloWorld extends java.lang.Object:
   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
index bc2ef49bac39e19a87761c0fb789c32c7aff8a6e..69ee446b2f65c88d127e170e763f5cf953bf7083 100644 (file)
@@ -10,10 +10,10 @@ public abstract class FancyHelloWorld extends java.lang.Object:
 
   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
@@ -55,8 +55,8 @@ public abstract class FancyHelloWorld extends java.lang.Object:
 
   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"
index d89b5acd97af4cf4d6d1d812f22c8f413f2ead6b..13dab828cc224a72a990e32f205523c137ab6d35 100644 (file)
@@ -10,10 +10,10 @@ public class HelloWorld extends java.lang.Object:
 
   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))
index 4745c2af0eccfb77b32ab809e6cbdd762feaa04a..4d3b2775df73e47481f236d08c3339008f9b9242 100644 (file)
@@ -9,7 +9,7 @@ public class DynamicHelloWorld extends java.lang.Object implements java.io.Seria
 
   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;
@@ -18,7 +18,7 @@ public class DynamicHelloWorld extends java.lang.Object implements java.io.Seria
     |               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"
index a32fad0f71b7eb3812140a4ffe65a2d642ba3d6f..f5704a576711b8c2787b48fad8647364f721fa9f 100644 (file)
@@ -19,10 +19,10 @@ public class FieldyHelloWorld extends java.lang.Object:
 
   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
index fc806f81024f42c37d262a724a623f6349b4bfdc..fed62e3c72e7a8dc352adf512994deb20f073ce3 100644 (file)
@@ -13,12 +13,12 @@ public class HelloWorld extends java.lang.Object:
 
   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))
index 6bc961dabfc0dc5b9455297597c1ea378fc22fa9..dcb25de154a0d8f2505cb44778c162731d14af45 100644 (file)
@@ -15,12 +15,12 @@ public class HelloWorld extends java.lang.Object:
 
   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))
index 910465ee10adf1af86e2f1dc74e8908905f41d95..cf1eb20f88b6a60688d9f9a7bd5cac3c33471bb3 100644 (file)
@@ -28,7 +28,7 @@ public class HelloWorld extends java.lang.Object:
                     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
@@ -38,7 +38,7 @@ public class HelloWorld extends java.lang.Object:
     | 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
index 95a629d12e694f26ca89691f3be421bec67fe7b7..7e313b9113499ed04b61cbad61d8ed91f0cc516d 100644 (file)
@@ -42,7 +42,7 @@ public class DynamicHelloWorld extends java.lang.Object implements java.io.Seria
                     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;