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 */
7public class TwrForVariable2 implements AutoCloseable {
8    public static void main(String... args) {
9        TwrForVariable2 v = new TwrForVariable2();
10        TwrForVariable3[] v2 = new TwrForVariable3[1];
11        TwrForVariable3[][] v3 = new TwrForVariable3[1][1];
12
13        try (final v) {
14            fail("no modifiers before variables");
15        }
16        try (@Deprecated v) {
17            fail("no annotations before variables");
18        }
19        try (v;;) {
20            fail("illegal double semicolon");
21        }
22        try ((v)) {
23            fail("parentheses not allowed");
24        }
25        try (v2[0]) {
26            fail("array access not allowed");
27        }
28        try (v3[0][0]) {
29            fail("array access not allowed");
30        }
31        try (args.length == 0 ? v : v) {
32            fail("general expressions not allowed");
33        }
34        try ((TwrForVariable2)null) {
35            fail("null as variable is not allowed");
36        }
37    }
38
39    static void fail(String reason) {
40        throw new RuntimeException(reason);
41    }
42
43    public void close() {
44    }
45
46}
47