aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraclement <aclement>2005-01-11 11:22:15 +0000
committeraclement <aclement>2005-01-11 11:22:15 +0000
commit603b063ecd2943e20f099712d9b754b19a380fee (patch)
treea3649ac5aa4e1a0ab475d5bee2a653785249f168
parent797b6a6afb75b14dc530bc0831566e110da3ae91 (diff)
downloadaspectj-603b063ecd2943e20f099712d9b754b19a380fee.tar.gz
aspectj-603b063ecd2943e20f099712d9b754b19a380fee.zip
Fixes for 78021, 79554 - both to do with us breaking the exception table for a method on weaving *if* finally blocks are involved.
-rw-r--r--tests/bugs150/PR78021.java45
-rw-r--r--tests/bugs150/PR79554.java41
-rw-r--r--tests/src/org/aspectj/systemtest/AllTests.java4
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java40
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java (renamed from tests/src/org/aspectj/systemtest/ajc150/AllTestsJava5_binaryWeaving.java)7
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/TestUtils.java2
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java35
-rw-r--r--weaver/testdata/AfterFancyHelloWorld.txt18
-rw-r--r--weaver/testdata/AfterHelloWorld.txt1
-rw-r--r--weaver/testdata/AfterThrowingFancyHelloWorld.txt18
-rw-r--r--weaver/testdata/AfterThrowingHelloWorld.txt1
-rw-r--r--weaver/testdata/AfterThrowingParamFancyHelloWorld.txt18
12 files changed, 189 insertions, 41 deletions
diff --git a/tests/bugs150/PR78021.java b/tests/bugs150/PR78021.java
new file mode 100644
index 000000000..66c86d339
--- /dev/null
+++ b/tests/bugs150/PR78021.java
@@ -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
index 000000000..5bab1d270
--- /dev/null
+++ b/tests/bugs150/PR79554.java
@@ -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!");
+ }
+}
diff --git a/tests/src/org/aspectj/systemtest/AllTests.java b/tests/src/org/aspectj/systemtest/AllTests.java
index 961d99693..22d673892 100644
--- a/tests/src/org/aspectj/systemtest/AllTests.java
+++ b/tests/src/org/aspectj/systemtest/AllTests.java
@@ -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
index 000000000..e0b22155a
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java
@@ -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/AllTestsJava5_binaryWeaving.java b/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java
index 353b5d07d..d138eb64b 100644
--- a/tests/src/org/aspectj/systemtest/ajc150/AllTestsJava5_binaryWeaving.java
+++ b/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java
@@ -19,13 +19,16 @@ import junit.framework.TestSuite;
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
-public class AllTestsJava5_binaryWeaving {
+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);
@@ -33,6 +36,8 @@ public class AllTestsJava5_binaryWeaving {
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/TestUtils.java b/tests/src/org/aspectj/systemtest/ajc150/TestUtils.java
index b62400c7c..dbaf6917d 100644
--- a/tests/src/org/aspectj/systemtest/ajc150/TestUtils.java
+++ b/tests/src/org/aspectj/systemtest/ajc150/TestUtils.java
@@ -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) {
diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
index 9c002bd9c..88f397818 100644
--- a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
+++ b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
@@ -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);
}
diff --git a/weaver/testdata/AfterFancyHelloWorld.txt b/weaver/testdata/AfterFancyHelloWorld.txt
index b693040af..04fe22f18 100644
--- a/weaver/testdata/AfterFancyHelloWorld.txt
+++ b/weaver/testdata/AfterFancyHelloWorld.txt
@@ -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
diff --git a/weaver/testdata/AfterHelloWorld.txt b/weaver/testdata/AfterHelloWorld.txt
index 4c0e6db53..190674778 100644
--- a/weaver/testdata/AfterHelloWorld.txt
+++ b/weaver/testdata/AfterHelloWorld.txt
@@ -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
diff --git a/weaver/testdata/AfterThrowingFancyHelloWorld.txt b/weaver/testdata/AfterThrowingFancyHelloWorld.txt
index 3323beea6..572e86072 100644
--- a/weaver/testdata/AfterThrowingFancyHelloWorld.txt
+++ b/weaver/testdata/AfterThrowingFancyHelloWorld.txt
@@ -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
diff --git a/weaver/testdata/AfterThrowingHelloWorld.txt b/weaver/testdata/AfterThrowingHelloWorld.txt
index 6b307e761..822f1cd6c 100644
--- a/weaver/testdata/AfterThrowingHelloWorld.txt
+++ b/weaver/testdata/AfterThrowingHelloWorld.txt
@@ -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
diff --git a/weaver/testdata/AfterThrowingParamFancyHelloWorld.txt b/weaver/testdata/AfterThrowingParamFancyHelloWorld.txt
index ecc17dcbd..08a2b89f4 100644
--- a/weaver/testdata/AfterThrowingParamFancyHelloWorld.txt
+++ b/weaver/testdata/AfterThrowingParamFancyHelloWorld.txt
@@ -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