aboutsummaryrefslogtreecommitdiffstats
path: root/tests/features152/synchronization/transformed/Fourteen.java
blob: 62a339826f6dfd13332861051f344760e54f9e1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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");
		}
	}

}