The compiler could check for me if I'm already inside a synchronized method or block and am trying to enter a synchronized block that locks the same lock as the outer lock (e.g. this). Yes, I know the spec says you can grab a lock more than once. The point is there's almost always a mistake when someone writes:
public class SyncSync {
public synchronized void method() {
System.out.println("before");
synchronized (this) {
System.out.println("inside");
}
System.out.println("after");
}
because the before and after code is really inside the locked region, or they don't need the inner synchronized block.
... peter 10/11/96
public class SyncSync {
public synchronized void method() {
System.out.println("before");
synchronized (this) {
System.out.println("inside");
}
System.out.println("after");
}
because the before and after code is really inside the locked region, or they don't need the inner synchronized block.
... peter 10/11/96
- duplicates
-
JDK-4128179 # Add a lint-like facility to javac
-
- Closed
-