]> source.dussan.org Git - aspectj.git/commitdiff
Fix for Bugzilla Bug 67774
authoraclement <aclement>
Mon, 2 Aug 2004 13:43:43 +0000 (13:43 +0000)
committeraclement <aclement>
Mon, 2 Aug 2004 13:43:43 +0000 (13:43 +0000)
   Nullpointer-exception in pointcuts using withincode() clause

tests/ajcTests.xml
tests/bugs/WithincodeNPE01.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java

index 8b42152d32712debcc1a29df0417bb2fda3e0745..e7031e59c2d2189965008be6a84377e93603c225 100644 (file)
         </compile>
     </ajc-test>
     
+    <ajc-test dir="bugs"
+               pr="67774" title="Nullpointer-Exception when defining a withincode() pointcut">
+        <compile files="WithincodeNPE01.java">
+          <!-- there are 3 join points that result in decw match, but 2 are on the same line! -->
+          <message kind="warning" line="2" text="In String ctor"/>
+          <message kind="warning" line="11" text="In String ctor"/>
+        </compile>
+    </ajc-test>
 </suite>
diff --git a/tests/bugs/WithincodeNPE01.java b/tests/bugs/WithincodeNPE01.java
new file mode 100644 (file)
index 0000000..8e7accb
--- /dev/null
@@ -0,0 +1,13 @@
+aspect B {
+  public A.new(String s) { }
+  public void A.foo() { int i = 1; }
+  
+  declare warning: withincode(void main(..)): "X"; // Would NPE without the fix for PR67774
+  
+  declare warning: withincode(A.new(String)): "In String ctor";
+  
+}
+
+class A {
+  private final static String name = A.class.getName();
+}
\ No newline at end of file
index 3c0588a39d8b64f53675fc63e81ec778f0579c67..e81c43ff2f55142adbd2097ca0d2d96482d067b3 100644 (file)
@@ -1015,6 +1015,10 @@ public class BcelShadow extends Shadow {
     public Member getEnclosingCodeSignature() {
        if (getKind().isEnclosingKind()) {
                return getSignature();
+       } else if (getKind() == Shadow.PreInitialization) {
+          // PreInit doesn't enclose code but its signature
+          // is correctly the signature of the ctor.
+         return getSignature();
        } else if (enclosingShadow == null) {
                return getEnclosingMethod().getMemberView();
        } else {