TwrForVariable2.java revision 2726:f62d01419621
1298770Sdelphij/* @test /nodynamiccopyright/ 2290001Sglebius * @bug 7196163 3290001Sglebius * @summary Verify that an improper combination of modifiers and variable is rejected 4290001Sglebius * in an operand to try-with-resources 5290001Sglebius * @compile/fail/ref=TwrForVariable2.out -XDrawDiagnostics -Xlint:-options TwrForVariable2.java 6298770Sdelphij */ 7290001Sglebiuspublic class TwrForVariable2 implements AutoCloseable { 8290001Sglebius public static void main(String... args) { 9290001Sglebius TwrForVariable2 v = new TwrForVariable2(); 10290001Sglebius TwrForVariable3[] v2 = new TwrForVariable3[1]; 11290001Sglebius 12290001Sglebius try (final v) { 13290001Sglebius fail("no modifiers before variables"); 14290001Sglebius } 15290001Sglebius try (@Deprecated v) { 16290001Sglebius fail("no annotations before variables"); 17290001Sglebius } 18290001Sglebius try (v;;) { 19290001Sglebius fail("illegal double semicolon"); 20290001Sglebius } 21290001Sglebius try ((v)) { 22290001Sglebius fail("parentheses not allowed"); 23290001Sglebius } 24290001Sglebius try (v2[0]) { 25290001Sglebius fail("array access not allowed"); 26290001Sglebius } 27290001Sglebius try (args.length == 0 ? v : v) { 28290001Sglebius fail("general expressions not allowed"); 29290001Sglebius } 30290001Sglebius } 31290001Sglebius 32290001Sglebius static void fail(String reason) { 33290001Sglebius throw new RuntimeException(reason); 34290001Sglebius } 35290001Sglebius 36290001Sglebius public void close() { 37290001Sglebius } 38290001Sglebius 39290001Sglebius} 40290001Sglebius