From a778ac41009cdc13412ca79cf7a1649ccec93571 Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 21 Dec 2005 17:21:57 +0000 Subject: [PATCH] proper fix for 121385. --- tests/bugs150/pr121385/A.java | 16 +++++++ tests/bugs150/pr121385/ConcreteWorld.aj | 5 +++ tests/bugs150/pr121385/Hello.java | 16 +++++++ tests/bugs150/pr121385/World.aj | 24 +++++++++++ tests/bugs150/pr121385/WorldAt.java | 10 +++++ tests/bugs150/pr121385/ant.xml | 43 +++++++++++++++++++ tests/bugs150/pr121385/aop.xml | 19 ++++++++ .../systemtest/ajc150/Ajc150Tests.java | 7 ++- .../org/aspectj/systemtest/ajc150/ajc150.xml | 24 +++++++++++ .../org/aspectj/weaver/bcel/BcelAdvice.java | 7 ++- .../org/aspectj/weaver/bcel/BcelShadow.java | 5 ++- 11 files changed, 169 insertions(+), 7 deletions(-) create mode 100644 tests/bugs150/pr121385/A.java create mode 100644 tests/bugs150/pr121385/ConcreteWorld.aj create mode 100644 tests/bugs150/pr121385/Hello.java create mode 100644 tests/bugs150/pr121385/World.aj create mode 100644 tests/bugs150/pr121385/WorldAt.java create mode 100644 tests/bugs150/pr121385/ant.xml create mode 100644 tests/bugs150/pr121385/aop.xml diff --git a/tests/bugs150/pr121385/A.java b/tests/bugs150/pr121385/A.java new file mode 100644 index 000000000..fd94e0a30 --- /dev/null +++ b/tests/bugs150/pr121385/A.java @@ -0,0 +1,16 @@ +import org.aspectj.lang.annotation.*; + + abstract aspect X { + void around(): execution(* foo(..)) {} +} + + +@Aspect class B extends X { } + +public class A { + public void foo() { } + +public static void main(String []argv) { + new A().foo(); +} +} diff --git a/tests/bugs150/pr121385/ConcreteWorld.aj b/tests/bugs150/pr121385/ConcreteWorld.aj new file mode 100644 index 000000000..cb1716509 --- /dev/null +++ b/tests/bugs150/pr121385/ConcreteWorld.aj @@ -0,0 +1,5 @@ +public aspect ConcreteWorld extends World { + pointcut greeting() : + execution(* Hello.sayWorld(..)) + || execution(* Hello.sayHello(..)); +} diff --git a/tests/bugs150/pr121385/Hello.java b/tests/bugs150/pr121385/Hello.java new file mode 100644 index 000000000..833ee1d3e --- /dev/null +++ b/tests/bugs150/pr121385/Hello.java @@ -0,0 +1,16 @@ +public class Hello { + + public static void main(String[] args) { + sayHello(); + } + + public static void sayHello() { + System.out.println("Hello"); + sayWorld(); + } + + public static int sayWorld() { + System.out.println("World"); + return 0; + } +} diff --git a/tests/bugs150/pr121385/World.aj b/tests/bugs150/pr121385/World.aj new file mode 100644 index 000000000..ac3fd5cc6 --- /dev/null +++ b/tests/bugs150/pr121385/World.aj @@ -0,0 +1,24 @@ +import org.aspectj.lang.Signature; +import org.aspectj.lang.JoinPoint; +public abstract aspect World { + //private Object result; + pointcut greeting() : execution(* Hello.sayWorld(..)); + + Object around(): greeting() { + System.out.println("around start!"); + Object result = proceed(); + System.out.println("around end!"); + return result; + } + +// before() : greeting() { +// Signature signature = thisJoinPoint.getSignature(); +// System.out.println("before " + signature.getName()); +// } + +// after() returning () : greeting() { +// Signature signature = thisJoinPoint.getSignature(); +// System.out.println("after " + signature.getName()); +// } + +} diff --git a/tests/bugs150/pr121385/WorldAt.java b/tests/bugs150/pr121385/WorldAt.java new file mode 100644 index 000000000..1d142de59 --- /dev/null +++ b/tests/bugs150/pr121385/WorldAt.java @@ -0,0 +1,10 @@ +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; + +@Aspect +public abstract class WorldAt { + + @Pointcut("execution(* Hello.sayWorld(..))") + void greeting() {} + +} diff --git a/tests/bugs150/pr121385/ant.xml b/tests/bugs150/pr121385/ant.xml new file mode 100644 index 000000000..994778ceb --- /dev/null +++ b/tests/bugs150/pr121385/ant.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/bugs150/pr121385/aop.xml b/tests/bugs150/pr121385/aop.xml new file mode 100644 index 000000000..b5e25899e --- /dev/null +++ b/tests/bugs150/pr121385/aop.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index effaf6eeb..87a4eea60 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -41,7 +41,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { protected File getSpecFile() { return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); } - + public void testMixingCodeStyles_pr121385() { runTest("mixing aspect styles");} public void testTypeVars_pr121575() { runTest("different numbers of type vars");} public void testTypeVars_pr121575_2() { runTest("different numbers of type vars - 2");} public void testTypeVars_pr121575_3() { runTest("different numbers of type vars - 3");} @@ -869,6 +869,11 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("abstract perthis in @AspectJ"); } + public void testNPEInBcelAdviceWithConcreteAspect_pr121385() { + runTest("override protected pointcut in aop.xml concrete aspect"); + } + + // helper methods..... public SyntheticRepository createRepos(File cpentry) { diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 34e9cb069..6a343d5f1 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -11,6 +11,12 @@ + + + + + + @@ -6207,5 +6213,23 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java index 5d6a5fcb6..7691136e8 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java @@ -400,7 +400,9 @@ public class BcelAdvice extends Advice { if (exposedState.getAspectInstance() != null) { il.append(BcelRenderer.renderExpr(fact, world, exposedState.getAspectInstance())); } - final boolean isAnnotationStyleAspect = getConcreteAspect()!=null && getConcreteAspect().isAnnotationStyleAspect(); + // pr121385 + boolean x = this.getDeclaringAspect().resolve(world).isAnnotationStyleAspect(); + final boolean isAnnotationStyleAspect = getConcreteAspect()!=null && getConcreteAspect().isAnnotationStyleAspect() && x; boolean previousIsClosure = false; for (int i = 0, len = exposedState.size(); i < len; i++) { if (exposedState.isErroneousVar(i)) continue; // Erroneous vars have already had error msgs reported! @@ -454,13 +456,10 @@ public class BcelAdvice extends Advice { } } else if (hasExtraParameter()) { previousIsClosure = false; - //extra var can be null here (@Aj aspect extends abstract code style, advice in code style) - if (extraVar != null) { extraVar.appendLoadAndConvert( il, fact, getExtraParameterType().resolve(world)); - } } else { previousIsClosure = false; getConcreteAspect().getWorld().getMessageHandler().handleMessage( diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index 1e8312eb0..3ff0d1764 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -2221,7 +2221,7 @@ public class BcelShadow extends Shadow { munger.getAdviceArgSetup( this, null, - (munger.getConcreteAspect().isAnnotationStyleAspect())? + (munger.getConcreteAspect().isAnnotationStyleAspect() && munger.getDeclaringAspect()!=null && munger.getDeclaringAspect().resolve(world).isAnnotationStyleAspect())? this.loadThisJoinPoint(): new InstructionList(InstructionConstants.ACONST_NULL))); // adviceMethodInvocation = @@ -2667,7 +2667,8 @@ public class BcelShadow extends Shadow { } // ATAJ for @AJ aspect we need to link the closure with the joinpoint instance - if (munger.getConcreteAspect()!=null && munger.getConcreteAspect().isAnnotationStyleAspect()) { + if (munger.getConcreteAspect()!=null && munger.getConcreteAspect().isAnnotationStyleAspect() + && munger.getDeclaringAspect()!=null && munger.getDeclaringAspect().resolve(world).isAnnotationStyleAspect()) { closureInstantiation.append(Utility.createInvoke( getFactory(), getWorld(), -- 2.39.5