summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/features152/synchronization/transformed/Fourteen.java46
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java4
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/synchronization.xml8
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java3
4 files changed, 60 insertions, 1 deletions
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 @@
</stderr>
</run>
</ajc-test>
+
+
+ <ajc-test dir="features152/synchronization/transformed" title="joinpoints enabled but no lock">
+ <compile files="Fourteen.java" options="-Xjoinpoints:synchronization">
+ <!--message kind="warning" line="8" text="advice matching the synchronized "/-->
+ </compile>
+ <run class="Fourteen"/>
+ </ajc-test>
</suite>
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 =