1 /* @test /nodynamiccopyright/ 2 * @bug 7196163 3 * @summary Verify that an improper combination of modifiers and variable is rejected 4 * in an operand to try-with-resources 5 * @compile/fail/ref=TwrForVariable2.out -XDrawDiagnostics -Xlint:-options TwrForVariable2.java 6 */ 7 public class TwrForVariable2 implements AutoCloseable { 8 public static void main(String... args) { 9 TwrForVariable2 v = new TwrForVariable2(); 10 TwrForVariable3[] v2 = new TwrForVariable3[1]; 11 12 try (final v) { 13 fail("no modifiers before variables"); 14 } 15 try (@Deprecated v) { 16 fail("no annotations before variables"); 17 } 18 try (v;;) { 19 fail("illegal double semicolon"); 20 } 21 try ((v)) { 22 fail("parentheses not allowed"); 23 } 24 try (v2[0]) { 25 fail("array access not allowed"); 26 } 27 try (args.length == 0 ? v : v) { 28 fail("general expressions not allowed"); 29 } 30 try ((TwrForVariable2)null) { 31 fail("null as variable is not allowed"); 32 } 33 } 34 35 static void fail(String reason) { 36 throw new RuntimeException(reason); 37 } 38 39 public void close() { 40 } 41 42 }