From 945a257776a5879251ccb1b90cf24fd1d89bcfe6 Mon Sep 17 00:00:00 2001 From: aclement Date: Tue, 22 Aug 2006 15:22:06 +0000 Subject: [PATCH] fixes for 149560: (1) correct the bcel code for creating clinit call (2) don't let singleton aspects be implemented as late type mungers, the clinit manipulation breaks. --- tests/bugs153/pr149560/AnnStyle.java | 20 +++++++++++++ tests/bugs153/pr149560/CodeStyle.java | 17 +++++++++++ .../systemtest/ajc153/Ajc153Tests.java | 4 ++- .../org/aspectj/systemtest/ajc153/ajc153.xml | 28 +++++++++++++++++++ .../tools/MultiProjectIncrementalTests.java | 8 +++--- .../weaver/bcel/BcelPerClauseAspectAdder.java | 2 +- .../aspectj/weaver/patterns/PerSingleton.java | 12 ++++++-- 7 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 tests/bugs153/pr149560/AnnStyle.java create mode 100644 tests/bugs153/pr149560/CodeStyle.java diff --git a/tests/bugs153/pr149560/AnnStyle.java b/tests/bugs153/pr149560/AnnStyle.java new file mode 100644 index 000000000..1941e6ca7 --- /dev/null +++ b/tests/bugs153/pr149560/AnnStyle.java @@ -0,0 +1,20 @@ +import org.aspectj.lang.annotation.*; +import org.aspectj.lang.*; + +@Aspect +class MyAspect { + @After("staticinitialization(*)") + public void x(JoinPoint.StaticPart thisJoinPointStaticPart) { + System.out.println("after initialization "+thisJoinPointStaticPart); + } +} + +public aspect AnnStyle { + + static { + } + + public static void main(String []argv) { + System.out.println("InstanceExists?"+Aspects.hasAspect(MyAspect.class)); + } +} diff --git a/tests/bugs153/pr149560/CodeStyle.java b/tests/bugs153/pr149560/CodeStyle.java new file mode 100644 index 000000000..09aaf48cd --- /dev/null +++ b/tests/bugs153/pr149560/CodeStyle.java @@ -0,0 +1,17 @@ +import org.aspectj.lang.*; + +aspect MyAspect { + after(): staticinitialization(*) { + System.out.println("after initialization "+thisJoinPointStaticPart); + } +} + +public aspect CodeStyle { + + static { + } + + public static void main(String []argv) { + System.out.println("InstanceExists?"+Aspects.hasAspect(MyAspect.class)); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java b/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java index b211e5cf3..b366d6798 100644 --- a/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java @@ -27,7 +27,9 @@ public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase { // public void testArgnamesAndJavac_pr148381() { runTest("argNames and javac");} // public void testCFlowXMLAspectLTW_pr149096() { runTest("cflow xml concrete aspect"); } // public void testAmbiguousBinding_pr121805() { runTest("ambiguous binding");} - public void testIncorrectDeprecatedAnnotationProcessing_pr154332() { runTest("incorrect deprecated annotation processing");} + public void testIncorrectStaticinitializationWeaving_pr149560_1() { runTest("incorrect staticinitialization weaving - codestyle");} + public void testIncorrectStaticinitializationWeaving_pr149560_2() { runTest("incorrect staticinitialization weaving - annstyle");} + public void testIncorrectDeprecatedAnnotationProcessing_pr154332() { runTest("incorrect deprecated annotation processing");} public void testPipeliningProblemWithAnnotationsDecp_pr153380_1() { runTest("pipelining decps");} public void testUnwantedPointcutWarning_pr148219() { runTest("unwanted warning for pointcut");} public void testDecpAndCflowadderMungerClash_pr152631() { runTest("decp and cflowadder munger clash");} diff --git a/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml b/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml index 06cc9c371..f7586c342 100644 --- a/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml +++ b/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml @@ -305,4 +305,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java b/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java index 3dc02895c..e241d5f55 100644 --- a/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java +++ b/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java @@ -658,16 +658,16 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa assertTrue("Should be zero but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==0); alter("PR141956","inc1"); build("PR141956"); - assertTrue("Should be only one but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==1); + assertTrue("Should be two but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==2); alter("PR141956","inc1"); build("PR141956"); - assertTrue("Should be only one but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==1); + assertTrue("Should be two but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==2); alter("PR141956","inc1"); build("PR141956"); - assertTrue("Should be only one but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==1); + assertTrue("Should be two but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==2); alter("PR141956","inc1"); build("PR141956"); - assertTrue("Should be only one but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==1); + assertTrue("Should be two but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==2); } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelPerClauseAspectAdder.java b/weaver/src/org/aspectj/weaver/bcel/BcelPerClauseAspectAdder.java index 45104a7a6..38d385691 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelPerClauseAspectAdder.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelPerClauseAspectAdder.java @@ -264,7 +264,7 @@ public class BcelPerClauseAspectAdder extends BcelTypeMunger { clinit.getBody().append(il); clinit.addExceptionHandler( - tryStart, handler, handler, new ObjectType("java.lang.Throwable"), false + tryStart, handler.getPrev(), handler, new ObjectType("java.lang.Throwable"), false ); } diff --git a/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java b/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java index 1c9f66711..3852b6a7a 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java +++ b/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java @@ -107,9 +107,15 @@ public class PerSingleton extends PerClause { if (inAspect.isAnnotationStyleAspect() && !inAspect.isAbstract()) { //TODO will those change be ok if we add a serializable aspect ? // dig: "can't be Serializable/Cloneable unless -XserializableAspects" - inAspect.crosscuttingMembers.addLateTypeMunger( - inAspect.getWorld().makePerClauseAspect(inAspect, getKind()) - ); + if (getKind()==SINGLETON) { // pr149560 + inAspect.crosscuttingMembers.addTypeMunger( + inAspect.getWorld().makePerClauseAspect(inAspect, getKind()) + ); + } else { + inAspect.crosscuttingMembers.addLateTypeMunger( + inAspect.getWorld().makePerClauseAspect(inAspect, getKind()) + ); + } } //ATAJ inline around advice support -- 2.39.5