From 7f19ab47a3df5327c6246420354089d1db1c765f Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 2 Aug 2004 13:43:43 +0000 Subject: [PATCH] Fix for Bugzilla Bug 67774 Nullpointer-exception in pointcuts using withincode() clause --- tests/ajcTests.xml | 8 ++++++++ tests/bugs/WithincodeNPE01.java | 13 +++++++++++++ weaver/src/org/aspectj/weaver/bcel/BcelShadow.java | 4 ++++ 3 files changed, 25 insertions(+) create mode 100644 tests/bugs/WithincodeNPE01.java diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml index 8b42152d3..e7031e59c 100644 --- a/tests/ajcTests.xml +++ b/tests/ajcTests.xml @@ -7832,4 +7832,12 @@ + + + + + + + diff --git a/tests/bugs/WithincodeNPE01.java b/tests/bugs/WithincodeNPE01.java new file mode 100644 index 000000000..8e7accb23 --- /dev/null +++ b/tests/bugs/WithincodeNPE01.java @@ -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 diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index 3c0588a39..e81c43ff2 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -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 { -- 2.39.5