langtools/test/tools/javac/TryWithResources/TwrForVariable2.java
changeset 27844 8b5d79870a2f
child 34565 627464b87753
equal deleted inserted replaced
27843:a032fe725c78 27844:8b5d79870a2f
       
     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     }
       
    31 
       
    32     static void fail(String reason) {
       
    33         throw new RuntimeException(reason);
       
    34     }
       
    35 
       
    36     public void close() {
       
    37     }
       
    38 
       
    39 }