]> source.dussan.org Git - aspectj.git/commitdiff
Test and fix for Bugzilla Bug 62642
authoraclement <aclement>
Tue, 17 Aug 2004 14:04:29 +0000 (14:04 +0000)
committeraclement <aclement>
Tue, 17 Aug 2004 14:04:29 +0000 (14:04 +0000)
   proper handling of ExceptionInIntializer inside <clinit> in presence of after throwing advice

tests/bugs/pr62642.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java
tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java

diff --git a/tests/bugs/pr62642.java b/tests/bugs/pr62642.java
new file mode 100644 (file)
index 0000000..30cc506
--- /dev/null
@@ -0,0 +1,40 @@
+class C {
+         static int x = 13;
+         int y;
+
+         public C() {
+           y= 14;
+         }
+
+         public static void main(String args[]) { 
+        
+               C m = new C();
+               m.y = 3;
+               System.out.println("hi");
+         }
+}
+
+public class pr62642 {
+    public static void main(String[] args) {
+        try {
+         C.main(null);   
+        } catch (ExceptionInInitializerError eiie) {
+               System.err.println("EIIE="+eiie.toString());
+            System.err.println("CAUSE="+eiie.getCause().toString());
+        }
+       }
+}
+
+
+aspect Aspect {
+
+    before () :  within(*) && !within(pr62642) { 
+        System.out.println("BEFORE "+ thisJoinPointStaticPart.getKind() +
+                                " at " + thisJoinPointStaticPart.getSourceLocation());
+       }
+
+       after ()  : within(*) && !within(pr62642)  { 
+        System.out.println("AFTER " + thisJoinPointStaticPart.getKind() +
+                                " at " + thisJoinPointStaticPart.getSourceLocation());
+       }
+}
\ No newline at end of file
index 391d5f89fcc4cf24a68f40b9300af54cc4a28335..ec5513053a27878d2608b4af546cfba63eea69f2 100644 (file)
@@ -225,6 +225,14 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void test042_ITDaccessingPrivateMethod_pr67578_2() {
        runTest("Privileged Aspect Access Problem Across Packages (2)");
   }
-
+  
+  public void test043_pr62642_ExceptionInInitializerError() {
+    runTest("proper handling of ExceptionInIntializer inside clinit in presence of after throwing advice");
+    String s = getLastRunResult().getStdErr();
+    assertTrue("Output should contain java.lang.ExceptionInInitializerError but is '"+s+"'",
+            s.indexOf("java.lang.ExceptionInInitializerError")!=-1);
+    assertTrue("Output should contain 'CAUSE=org.aspectj.lang.NoAspectBoundException' but is '"+s+"'",
+            s.indexOf("CAUSE=org.aspectj.lang.NoAspectBoundException")!=-1);
+  }
 }
 
index 4b60da7acf9d9a3d63fc61d9d2be64a6873921ff..b687ae762cbfa9f332dba5882f49f63d08cee42a 100644 (file)
                        <message kind="error" line="7" text="The method returnNothing(Object) from the type ITD is not visible"/>
                </compile>
        </ajc-test>
+       
+       <ajc-test dir="bugs" pr="62642"
+               title="proper handling of ExceptionInIntializer inside clinit in presence of after throwing advice">
+               <compile files="pr62642.java"/>
+               <run class="pr62642">
+                       <message kind="error"/>
+               </run>
+       </ajc-test>
index 74345359226f6fe0eeded79b21c0706ccc29e2f4..9e6fd0c29d73d09b83ba92c10bfa91b66e4e7b94 100644 (file)
@@ -1201,6 +1201,24 @@ public class BcelShadow extends Shadow {
         BcelVar exceptionVar = genTempVar(catchType);
         exceptionVar.appendStore(handler, fact);
 
+        // pr62642
+        // I will now jump through some firey BCEL hoops to generate a trivial bit of code:
+        // if (exc instanceof ExceptionInInitializerError) 
+        //    throw (ExceptionInInitializerError)exc;
+        if (this.getEnclosingMethod().getName().equals("<clinit>")) {
+            ResolvedTypeX eiieType = world.resolve("java.lang.ExceptionInInitializerError");
+            ObjectType eiieBcelType = (ObjectType)BcelWorld.makeBcelType(eiieType);
+               InstructionList ih = new InstructionList(InstructionConstants.NOP);
+               handler.append(exceptionVar.createLoad(fact));
+               handler.append(fact.createInstanceOf(eiieBcelType));
+               BranchInstruction bi = 
+                InstructionFactory.createBranchInstruction(Constants.IFEQ,ih.getStart());
+               handler.append(bi);
+               handler.append(exceptionVar.createLoad(fact));
+               handler.append(fact.createCheckCast(eiieBcelType));
+               handler.append(InstructionConstants.ATHROW);
+               handler.append(ih);
+        }
         
         InstructionList endHandler = new InstructionList(
             exceptionVar.createLoad(fact));