langtools/test/tools/javac/TryWithResources/TwrForVariable2.java
author jlahoda
Wed, 09 Dec 2015 14:26:56 +0100
changeset 34565 627464b87753
parent 27844 8b5d79870a2f
permissions -rw-r--r--
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin Summary: A set of tests using t-w-r as variable in different positive and negative constructions Reviewed-by: abuckley, darcy, jlahoda, sadayapalam Contributed-by: sergei.pikalev@oracle.com

/* @test /nodynamiccopyright/
 * @bug 7196163
 * @summary Verify that an improper combination of modifiers and variable is rejected
 *          in an operand to try-with-resources
 * @compile/fail/ref=TwrForVariable2.out -XDrawDiagnostics -Xlint:-options TwrForVariable2.java
 */
public class TwrForVariable2 implements AutoCloseable {
    public static void main(String... args) {
        TwrForVariable2 v = new TwrForVariable2();
        TwrForVariable3[] v2 = new TwrForVariable3[1];
        TwrForVariable3[][] v3 = new TwrForVariable3[1][1];

        try (final v) {
            fail("no modifiers before variables");
        }
        try (@Deprecated v) {
            fail("no annotations before variables");
        }
        try (v;;) {
            fail("illegal double semicolon");
        }
        try ((v)) {
            fail("parentheses not allowed");
        }
        try (v2[0]) {
            fail("array access not allowed");
        }
        try (v3[0][0]) {
            fail("array access not allowed");
        }
        try (args.length == 0 ? v : v) {
            fail("general expressions not allowed");
        }
        try ((TwrForVariable2)null) {
            fail("null as variable is not allowed");
        }
    }

    static void fail(String reason) {
        throw new RuntimeException(reason);
    }

    public void close() {
    }

}