--- /dev/null
+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
--- /dev/null
+/*
+ * 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!");
+ }
+}
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;
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());
--- /dev/null
+/*******************************************************************************
+ * 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
--- /dev/null
+/*******************************************************************************
+ * 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;
+ }
+}
+++ /dev/null
-/*******************************************************************************
- * 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;
- }
-}
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) {
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;
}
- /** This proedure should not currently be used.
+ /** This procedure should not currently be used.
*/
// public void killNops() {
// InstructionHandle curr = body.getStart();
}
}
+ // 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:
// 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);
}
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
| | | 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))
| | | | | 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))
| | | | 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
| RETURN
method-execution(void HelloWorld.main(java.lang.String[]))
end public static void main(String[])
+
end public class HelloWorld
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))
| | | | | 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))
| | | | 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
| ATHROW
method-execution(void HelloWorld.main(java.lang.String[]))
end public static void main(String[])
+
end public class HelloWorld
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
| | 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