From f4289cd1511ef1977fecd10cb1949c78dfbb9e9c Mon Sep 17 00:00:00 2001 From: aclement Date: Tue, 1 Aug 2006 12:40:31 +0000 Subject: [PATCH] synchronization pointcut problem (see Fourteen.java for info) --- .../synchronization/transformed/Fourteen.java | 46 +++++++++++++++++++ .../ajc152/SynchronizationTransformTests.java | 4 ++ .../systemtest/ajc152/synchronization.xml | 8 ++++ .../aspectj/weaver/bcel/LazyMethodGen.java | 3 +- 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/features152/synchronization/transformed/Fourteen.java diff --git a/tests/features152/synchronization/transformed/Fourteen.java b/tests/features152/synchronization/transformed/Fourteen.java new file mode 100644 index 000000000..62a339826 --- /dev/null +++ b/tests/features152/synchronization/transformed/Fourteen.java @@ -0,0 +1,46 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.lang.reflect.*; + +/** + * We had a bug where if Xjoinpoints:synchronized was ON and yet no pointcuts used lock()/unlock() *and* + * a synchronized method was woven, then we got things wrong. We removed the synchronized modifier but + * never inserted the required monitorenter/exit block. + */ +public aspect Fourteen { + + public static void main(String[] args) throws Exception { + Class c = Class.forName("Fourteen"); + Method m = c.getMethod("b",null); + if (!Modifier.isSynchronized(m.getModifiers())) + throw new RuntimeException("Method b() should still be synchronized"); + } + + before(): call(* println(..)) {} + + // ... that does something ... + public synchronized void b() { + System.out.println("hello"); + } + + // ... that includes try/catch ... + public synchronized void c() { + try { + File f = new File("fred"); + FileInputStream fis = new FileInputStream(f); + } catch (IOException ioe) { + System.out.println("bang"); + } + } + + // ... with nested synchronized blocks ... + public synchronized void e() { + System.out.println("hello"); + synchronized (new String()) { + System.out.println("other"); + } + } + +} + diff --git a/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java b/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java index e48ee633e..75f57c8fe 100644 --- a/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java +++ b/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java @@ -170,6 +170,10 @@ public class SynchronizationTransformTests extends XMLBasedAjcTestCase { public void testUnlockPcdOnTransformedStaticMethodPreJ5() { runTest("unlock pcd on transformed static method - preJ5"); } + + public void testJoinpointsEnabledButNoLock() { + runTest("joinpoints enabled but no lock"); + } // more complex code sequences... public void testOtherTargeters() { diff --git a/tests/src/org/aspectj/systemtest/ajc152/synchronization.xml b/tests/src/org/aspectj/systemtest/ajc152/synchronization.xml index 0f9dbbfb6..d0cf6e0b2 100644 --- a/tests/src/org/aspectj/systemtest/ajc152/synchronization.xml +++ b/tests/src/org/aspectj/systemtest/ajc152/synchronization.xml @@ -581,5 +581,13 @@ + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java index 9e678df76..ddb77ace9 100644 --- a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java +++ b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java @@ -926,7 +926,8 @@ public final class LazyMethodGen implements Traceable { //killNops(); int flags = getAccessFlags(); - if (enclosingClass.getWorld().isJoinpointSynchronizationEnabled()) { + if (enclosingClass.getWorld().isJoinpointSynchronizationEnabled() && + enclosingClass.getWorld().areSynchronizationPointcutsInUse()) { flags = getAccessFlagsWithoutSynchronized(); } MethodGen gen = -- 2.39.5