1 /* 2 * @test /nodynamiccopyright/ 3 * @summary Check behavior of synzhronized key word on value instances and methods. 4 * @modules jdk.incubator.mvt 5 * @compile/fail/ref=CheckSynchronized.out --should-stop:ifError=PARSE -XDrawDiagnostics -Werror -Xlint:values CheckSynchronized.java 6 */ 7 @jdk.incubator.mvt.ValueCapableClass 8 final class CheckSynchronized { 9 synchronized void foo() { // <<-- ERROR, no monitor associated with `this' 10 } 11 void goo() { 12 synchronized(this) {} // <<-- ERROR, no monitor associated with `this' 13 } 14 synchronized static void zoo(CheckSynchronized cs) { // OK, static method. 15 synchronized(cs) { // <<-- ERROR, no monitor associated with value instance. 16 } 17 } 18 }