]> source.dussan.org Git - aspectj.git/commitdiff
synchronization pointcut problem (see Fourteen.java for info)
authoraclement <aclement>
Tue, 1 Aug 2006 12:40:31 +0000 (12:40 +0000)
committeraclement <aclement>
Tue, 1 Aug 2006 12:40:31 +0000 (12:40 +0000)
tests/features152/synchronization/transformed/Fourteen.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java
tests/src/org/aspectj/systemtest/ajc152/synchronization.xml
weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java

diff --git a/tests/features152/synchronization/transformed/Fourteen.java b/tests/features152/synchronization/transformed/Fourteen.java
new file mode 100644 (file)
index 0000000..62a3398
--- /dev/null
@@ -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");
+               }
+       }
+
+}
+
index e48ee633e8c26c715d2e638fd3effa588616441c..75f57c8fee1a1f6ed4fd06bc511337ac2339f6aa 100644 (file)
@@ -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() {
index 0f9dbbfb6cb3a398e9558e3fb666edc27412817c..d0cf6e0b2a9a1fcb08e3cd6e28797d2f3dd318f0 100644 (file)
         </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>
index 9e678df76afc5f5293ea9293dc65580099bcab2b..ddb77ace9246552d566bb5659e0aa2c2462c810e 100644 (file)
@@ -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 =