]> source.dussan.org Git - aspectj.git/commitdiff
Fixes for 78021, 79554 - both to do with us breaking the exception table for a method...
authoraclement <aclement>
Tue, 11 Jan 2005 11:22:15 +0000 (11:22 +0000)
committeraclement <aclement>
Tue, 11 Jan 2005 11:22:15 +0000 (11:22 +0000)
13 files changed:
tests/bugs150/PR78021.java [new file with mode: 0644]
tests/bugs150/PR79554.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/AllTests.java
tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/AllTestsJava5_binaryWeaving.java [deleted file]
tests/src/org/aspectj/systemtest/ajc150/TestUtils.java
weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
weaver/testdata/AfterFancyHelloWorld.txt
weaver/testdata/AfterHelloWorld.txt
weaver/testdata/AfterThrowingFancyHelloWorld.txt
weaver/testdata/AfterThrowingHelloWorld.txt
weaver/testdata/AfterThrowingParamFancyHelloWorld.txt

diff --git a/tests/bugs150/PR78021.java b/tests/bugs150/PR78021.java
new file mode 100644 (file)
index 0000000..66c86d3
--- /dev/null
@@ -0,0 +1,45 @@
+public class PR78021 {
+
+       protected static Integer counter = new Integer(4);
+
+       public static void main(String[] args) throws Exception {
+         try {
+           doSomething();
+           System.err.println("TEST HAS PASSED");
+         } catch (Exception e) {
+           System.err.println("TEST HAS FAILED: Exception thrown by doSomething: " +e.getMessage());
+           throw e;
+         }
+       }
+
+       public static void doSomething() {
+         int i = 0;
+         while (i++<1) { 
+           counter=null;
+           try {
+             counter = new Integer(4);
+             // The inclusion of the next line changes the weaving !  If it is included the woven code is wrong and the exception escapes
+              if (counter == null) { break; }
+             commit();
+           } catch (Throwable e) {
+             System.err.println("Caught exception " + e);
+           } finally {
+             System.err.println("In finally block");
+           }
+         }
+       }
+
+       protected static void commit() throws MyException {
+         System.err.println("Main.commit");
+       }
+}
+
+class MyException extends Exception { MyException(String s,String s2) { super(s); } }
+
+aspect SimpleExceptionThrowingAspect {
+   pointcut commitOperation() : call (* PR78021+.commit(..));
+
+   before() throws MyException : commitOperation() {
+        throw new MyException("Dummy My Exception", "55102");
+   }
+}
\ No newline at end of file
diff --git a/tests/bugs150/PR79554.java b/tests/bugs150/PR79554.java
new file mode 100644 (file)
index 0000000..5bab1d2
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Created on 22.10.2004
+ */
+
+/**
+ * @author Thomas Knauth
+ */
+public class PR79554
+{
+    public static void main(String[] args)
+    {
+        try
+        {
+               if ( args.length < 0 )
+               {
+                       System.out.println("Usage!");
+                       return;
+               }
+
+               throw new Exception();
+        }
+        catch ( Throwable e )
+        {
+            System.out.println( "exception caught!" );
+            //e.printStackTrace();
+        }
+        finally
+        {
+               System.out.println("finally block entered!");
+        }
+    }
+}
+
+aspect Aspect {
+
+       pointcut main(): execution(void main(String[]));
+  
+       after(): main(){
+         System.out.println("Aspect calling after main!");
+       }
+}
index 961d9969331fa383a7f3e811bd20d196e4360e9b..22d67389244bf80ea98b9844dcff9193565d42dd 100644 (file)
@@ -13,7 +13,7 @@ import org.aspectj.systemtest.ajc10x.Ajc10xTests;
 import org.aspectj.systemtest.ajc11.Ajc11Tests;
 import org.aspectj.systemtest.ajc120.Ajc120Tests;
 import org.aspectj.systemtest.ajc121.Ajc121Tests;
-import org.aspectj.systemtest.ajc150.AllTestsJava5_binaryWeaving;
+import org.aspectj.systemtest.ajc150.AllTestsAspectJ150;
 import org.aspectj.systemtest.aspectpath.AspectPathTests;
 import org.aspectj.systemtest.base.BaseTests;
 import org.aspectj.systemtest.design.DesignTests;
@@ -36,7 +36,7 @@ public class AllTests {
        public static Test suite() {
                TestSuite suite = new TestSuite("AspectJ System Test Suite - JDK 1.3");
                //$JUnit-BEGIN$
-               suite.addTest(AllTestsJava5_binaryWeaving.suite());
+               suite.addTest(AllTestsAspectJ150.suite());
                suite.addTest(Ajc121Tests.suite());
                suite.addTest(Ajc120Tests.suite());
                suite.addTest(Ajc11Tests.suite());
diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java
new file mode 100644 (file)
index 0000000..e0b2215
--- /dev/null
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2005 IBM 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ *    Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc150;
+
+import java.io.File;
+
+import org.aspectj.tools.ajc.CompilationResult;
+
+
+/**
+ */
+public class Ajc150TestsNoHarness extends TestUtils {
+
+  protected void setUp() throws Exception {
+       super.setUp();
+       baseDir = new File("../tests/bugs150");
+  }
+  
+  public void testIncorrectExceptionTableWhenBreakInMethod_pr78021() {
+       CompilationResult cR=ajc(baseDir,new String[]{"PR78021.java"});
+       if (verbose) { System.err.println(cR); System.err.println(cR.getStandardError());}
+       RunResult rR = run("PR78021");
+       if (verbose) {System.err.println(rR.getStdErr());}
+  }
+  
+  public void testIncorrectExceptionTableWhenReturnInMethod_pr79554() {
+       CompilationResult cR=ajc(baseDir,new String[]{"PR79554.java"});
+       if (verbose) { System.err.println(cR); System.err.println(cR.getStandardError());}
+       RunResult rR = run("PR79554");
+       if (verbose) {System.err.println(rR.getStdErr());}
+  }
+}
\ No newline at end of file
diff --git a/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java b/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java
new file mode 100644 (file)
index 0000000..d138eb6
--- /dev/null
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ *    Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc150;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author colyer
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class AllTestsAspectJ150 {
+
+       public static Test suite() {
+               TestSuite suite = new TestSuite("Java5 - binary weaving");
+               //$JUnit-BEGIN$
+               suite.addTestSuite(MigrationTests.class);
+               suite.addTest(Ajc150Tests.suite());
+               suite.addTestSuite(Ajc150TestsNoHarness.class); 
+               
+               // These are binary weaving tests
+               suite.addTest(AccBridgeMethods.suite());
+               suite.addTestSuite(CovarianceTests.class);
+               suite.addTestSuite(Enums.class);
+               suite.addTestSuite(Annotations.class);
+               suite.addTestSuite(AnnotationPointcutsTests.class);
+               suite.addTestSuite(VarargsTests.class);
+               suite.addTestSuite(AnnotationRuntimeTests.class);
+               
+               
+               //$JUnit-END$
+               return suite;
+       }
+}
diff --git a/tests/src/org/aspectj/systemtest/ajc150/AllTestsJava5_binaryWeaving.java b/tests/src/org/aspectj/systemtest/ajc150/AllTestsJava5_binaryWeaving.java
deleted file mode 100644 (file)
index 353b5d0..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 IBM 
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- *    Andy Clement - initial API and implementation
- *******************************************************************************/
-package org.aspectj.systemtest.ajc150;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * @author colyer
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
-public class AllTestsJava5_binaryWeaving {
-
-       public static Test suite() {
-               TestSuite suite = new TestSuite("Java5 - binary weaving");
-               //$JUnit-BEGIN$
-               suite.addTestSuite(MigrationTests.class);
-               suite.addTest(Ajc150Tests.suite());
-               suite.addTest(AccBridgeMethods.suite());
-               suite.addTestSuite(CovarianceTests.class);
-               suite.addTestSuite(Enums.class);
-               suite.addTestSuite(Annotations.class);
-               suite.addTestSuite(AnnotationPointcutsTests.class);
-               suite.addTestSuite(VarargsTests.class);
-               suite.addTestSuite(AnnotationRuntimeTests.class);
-               //$JUnit-END$
-               return suite;
-       }
-}
index b62400c7c7c4c23157bc3a32f4db8747ca994cea..dbaf6917d797d4537bc1bfb3fb43f21b595143fe 100644 (file)
@@ -21,7 +21,7 @@ import org.aspectj.tools.ajc.AjcTestCase;
 import org.aspectj.tools.ajc.CompilationResult;
 
 public abstract class TestUtils extends AjcTestCase {
-       private static final boolean verbose = false;
+       protected static final boolean verbose = false;
        protected File baseDir;
        
        protected CompilationResult binaryWeave(String inpath,String insource,int expErrors,int expWarnings) {
index 9c002bd9c10478782127d60043b9f69ccafe8189..88f3978183e8fc16f37a4d1bcfd8cc2f82c952b5 100644 (file)
@@ -22,6 +22,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.Stack;
@@ -972,7 +973,7 @@ public final class LazyMethodGen {
 
     }
 
-       /** This proedure should not currently be used.
+       /** This procedure should not currently be used.
         */
 //     public void killNops() {
 //     InstructionHandle curr = body.getStart();
@@ -1007,10 +1008,19 @@ public final class LazyMethodGen {
         }
     }
 
+    // Update to all these comments, ASC 11-01-2005
+    // The right thing to do may be to do more with priorities as
+    // we create new exception handlers, but that is a relatively
+    // complex task.  In the meantime, just taking account of the
+    // priority here enables a couple of bugs to be fixed to do
+    // with using return or break in code that contains a finally
+    // block (pr78021,pr79554).
+
     // exception ordering.
     // What we should be doing is dealing with priority inversions way earlier than we are
     // and counting on the tree structure.  In which case, the below code is in fact right.
     
+    
     // XXX THIS COMMENT BELOW IS CURRENTLY WRONG. 
     // An exception A preceeds an exception B in the exception table iff:
     
@@ -1022,15 +1032,20 @@ public final class LazyMethodGen {
     // but I don't trust the only implementation, TreeSet, to do the right thing.
     
     /* private */ static void insertHandler(ExceptionRange fresh, LinkedList l) {
-//        for (ListIterator iter = l.listIterator(); iter.hasNext();) {
-//            ExceptionRange r = (ExceptionRange) iter.next();
-//            if (fresh.getPriority() >= r.getPriority()) {
-//                iter.previous();
-//                iter.add(fresh);
-//                return;
-//            }            
-//        }
-        l.add(0, fresh);        
+       // Old implementation, simply:   l.add(0,fresh);
+       for (ListIterator iter = l.listIterator(); iter.hasNext();) {
+            ExceptionRange r = (ExceptionRange) iter.next();
+            int freal = fresh.getRealStart().getPosition();
+            int rreal = r.getRealStart().getPosition();
+            if (fresh.getPriority() >= r.getPriority()) {
+                iter.previous();
+                iter.add(fresh);
+                return;
+            }
+        }
+       
+       // we have reached the end
+        l.add(fresh);        
     }
 
 
index b693040afb1f812fb70edbd8a90a7941fd28ce86..04fe22f18a708bcc6f54a75fd00d519cba693e42 100644 (file)
@@ -19,11 +19,11 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     method-execution(void FancyHelloWorld.main(java.lang.String[]))
     | catch java.lang.Throwable -> E6
     | | field-get(java.io.PrintStream java.lang.System.out)
-    | | | catch java.lang.Throwable -> E5
+    | | | catch java.lang.Throwable -> E3
     | | | |         GETSTATIC java.lang.System.out Ljava/io/PrintStream;   (line 9)
-    | | | catch java.lang.Throwable -> E5
+    | | | catch java.lang.Throwable -> E3
     | | |           GOTO L0
-    | | |       E5: ASTORE 5
+    | | |       E3: ASTORE 5
     | | |           INVOKESTATIC Aspect.ajc_after_field_get ()V
     | | |           ALOAD 5
     | | |           ATHROW
@@ -32,8 +32,8 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     | | |           NOP
     | | field-get(java.io.PrintStream java.lang.System.out)
     | |             ASTORE_1
-    | | finally -> E4
-    | | | catch java.lang.Exception -> E3
+    | | finally -> E5
+    | | | catch java.lang.Exception -> E4
     | | | |         ALOAD_1     // java.io.PrintStream out   (line 11)
     | | | |         LDC "bye"
     | | | | method-call(void java.io.PrintStream.println(java.lang.String))
@@ -50,8 +50,8 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     | | | | |       NOP
     | | | | method-call(void java.io.PrintStream.println(java.lang.String))
     | | | |         GOTO L3
-    | | | catch java.lang.Exception -> E3
-    | | |       E3: ASTORE_2   (line 12)
+    | | | catch java.lang.Exception -> E4
+    | | |       E4: ASTORE_2   (line 12)
     | | |           ALOAD_1     // java.io.PrintStream out   (line 13)
     | | |           ALOAD_2     // java.lang.Exception e
     | | | method-call(void java.io.PrintStream.println(java.lang.Object))
@@ -67,9 +67,9 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     | | | |         INVOKESTATIC Aspect.ajc_after_method_call ()V
     | | | |         NOP
     | | | method-call(void java.io.PrintStream.println(java.lang.Object))
-    | | finally -> E4
+    | | finally -> E5
     | |             GOTO L3
-    | |         E4: ASTORE 4   (line 14)
+    | |         E5: ASTORE 4   (line 14)
     | |             JSR L4
     | |             ALOAD 4
     | |             ATHROW
index 4c0e6db53bae4c8da2b344123a11f8f1ef3d0727..190674778e5e07a1a314e08c6d7c43108cb14c58 100644 (file)
@@ -55,4 +55,5 @@ public class HelloWorld extends java.lang.Object:
     |               RETURN
     method-execution(void HelloWorld.main(java.lang.String[]))
   end public static void main(String[])
+
 end public class HelloWorld
index 3323beea64055f0ea7de107d21d686399b296ea7..572e860727785bb16cc6186d489eaf01a283361e 100644 (file)
@@ -17,19 +17,19 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     method-execution(void FancyHelloWorld.main(java.lang.String[]))
     | catch java.lang.Throwable -> E6
     | | field-get(java.io.PrintStream java.lang.System.out)
-    | | | catch java.lang.Throwable -> E5
+    | | | catch java.lang.Throwable -> E3
     | | | |         GETSTATIC java.lang.System.out Ljava/io/PrintStream;   (line 9)
-    | | | catch java.lang.Throwable -> E5
+    | | | catch java.lang.Throwable -> E3
     | | |           GOTO L0
-    | | |       E5: ASTORE 5
+    | | |       E3: ASTORE 5
     | | |           INVOKESTATIC Aspect.ajc_afterThrowing_field_get ()V
     | | |           ALOAD 5
     | | |           ATHROW
     | | |       L0: NOP
     | | field-get(java.io.PrintStream java.lang.System.out)
     | |             ASTORE_1
-    | | finally -> E4
-    | | | catch java.lang.Exception -> E3
+    | | finally -> E5
+    | | | catch java.lang.Exception -> E4
     | | | |         ALOAD_1     // java.io.PrintStream out   (line 11)
     | | | |         LDC "bye"
     | | | | method-call(void java.io.PrintStream.println(java.lang.String))
@@ -44,8 +44,8 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     | | | | |   L1: NOP
     | | | | method-call(void java.io.PrintStream.println(java.lang.String))
     | | | |         GOTO L3
-    | | | catch java.lang.Exception -> E3
-    | | |       E3: ASTORE_2   (line 12)
+    | | | catch java.lang.Exception -> E4
+    | | |       E4: ASTORE_2   (line 12)
     | | |           ALOAD_1     // java.io.PrintStream out   (line 13)
     | | |           ALOAD_2     // java.lang.Exception e
     | | | method-call(void java.io.PrintStream.println(java.lang.Object))
@@ -59,9 +59,9 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     | | | |         ATHROW
     | | | |     L2: NOP
     | | | method-call(void java.io.PrintStream.println(java.lang.Object))
-    | | finally -> E4
+    | | finally -> E5
     | |             GOTO L3
-    | |         E4: ASTORE 4   (line 14)
+    | |         E5: ASTORE 4   (line 14)
     | |             JSR L4
     | |             ALOAD 4
     | |             ATHROW
index 6b307e7619d155adf88041b29474c932431dbe18..822f1cd6c8098ed858fea0cbd6750bb155028993 100644 (file)
@@ -47,4 +47,5 @@ public class HelloWorld extends java.lang.Object:
     |               ATHROW
     method-execution(void HelloWorld.main(java.lang.String[]))
   end public static void main(String[])
+
 end public class HelloWorld
index ecc17dcbd3944402f4174614f2c01aea719fc005..08a2b89f457536bf3faa3600e011513da9ba7c29 100644 (file)
@@ -10,11 +10,11 @@ public abstract class FancyHelloWorld extends java.lang.Object:
   public static void main(String[]):
     method-execution(void FancyHelloWorld.main(java.lang.String[]))
     | field-get(java.io.PrintStream java.lang.System.out)
-    | | catch java.lang.Throwable -> E2
+    | | catch java.lang.Throwable -> E0
     | | |           GETSTATIC java.lang.System.out Ljava/io/PrintStream;   (line 9)
-    | | catch java.lang.Throwable -> E2
+    | | catch java.lang.Throwable -> E0
     | |             GOTO L0
-    | |         E2: ASTORE 5
+    | |         E0: ASTORE 5
     | |             ALOAD 5
     | |             INVOKESTATIC Aspect.ajc_afterThrowing_field_get (Ljava/lang/Throwable;)V
     | |             ALOAD 5
@@ -22,20 +22,20 @@ public abstract class FancyHelloWorld extends java.lang.Object:
     | |         L0: NOP
     | field-get(java.io.PrintStream java.lang.System.out)
     |               ASTORE_1
-    | finally -> E1
-    | | catch java.lang.Exception -> E0
+    | finally -> E2
+    | | catch java.lang.Exception -> E1
     | | |           ALOAD_1     // java.io.PrintStream out   (line 11)
     | | |           LDC "bye"
     | | |           INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V
     | | |           GOTO L1
-    | | catch java.lang.Exception -> E0
-    | |         E0: ASTORE_2   (line 12)
+    | | catch java.lang.Exception -> E1
+    | |         E1: ASTORE_2   (line 12)
     | |             ALOAD_1     // java.io.PrintStream out   (line 13)
     | |             ALOAD_2     // java.lang.Exception e
     | |             INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/Object;)V
-    | finally -> E1
+    | finally -> E2
     |               GOTO L1
-    |           E1: ASTORE 4   (line 14)
+    |           E2: ASTORE 4   (line 14)
     |               JSR L2
     |               ALOAD 4
     |               ATHROW