< prev index next >

test/langtools/tools/javac/TryWithResources/TwrForVariable3.java

Print this page

 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) {

 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) {
< prev index next >