1 /* @test /nodynamiccopyright/
2 * @bug 7196163
3 * @summary Verify that improper expressions used as an operand to try-with-resources are rejected.
4 * @compile/fail/ref=TwrForVariable3.out -XDrawDiagnostics -Xlint:-options TwrForVariable3.java
5 */
6 public class TwrForVariable3 implements AutoCloseable {
7 public static void main(String... args) {
8 TwrForVariable3 v1 = new TwrForVariable3();
9 Object v2 = new Object();
10
11 try (v2) {
12 fail("no an AutoCloseable");
13 }
14 try (java.lang.Object) {
15 fail("not a variable access");
16 }
17 try (java.lang) {
18 fail("not a variable access");
19 }
20 }
21
22 static void fail(String reason) {
23 throw new RuntimeException(reason);
24 }
25
26 public void close() {
27 }
28
29 }
|
1 /* @test /nodynamiccopyright/
2 * @bug 7196163
3 * @summary Verify that improper expressions used as an operand to try-with-resources are rejected.
4 * @compile/fail/ref=TwrForVariable3.out -XDrawDiagnostics -Xlint:-options TwrForVariable3.java
5 */
6 public class TwrForVariable3 implements AutoCloseable {
7 public static void main(String... args) {
8 TwrForVariable3 v1 = new TwrForVariable3();
9 Object v2 = new Object();
10 Object v3 = new Object() {
11 public void close() {
12 }
13 };
14
15 try (v2) {
16 fail("not an AutoCloseable");
17 }
18 try (v3) {
19 fail("not an AutoCloseable although has close() method");
20 }
21 try (java.lang.Object) {
22 fail("not a variable access");
23 }
24 try (java.lang) {
25 fail("not a variable access");
26 }
27 }
28
29 static void fail(String reason) {
30 throw new RuntimeException(reason);
31 }
32
33 public void close() {
34 }
35
36 }
|