test/tools/javac/TryWithResources/TwrOnNonResource.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/TryWithResources/TwrOnNonResource.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,30 @@
     1.4 +/*
     1.5 + * @test  /nodynamiccopyright/
     1.6 + * @bug 6911256 6964740 7013420
     1.7 + * @author Joseph D. Darcy
     1.8 + * @summary Verify invalid TWR block is not accepted.
     1.9 + * @compile/fail -source 6 TwrOnNonResource.java
    1.10 + * @compile/fail/ref=TwrOnNonResource.out -XDrawDiagnostics TwrOnNonResource.java
    1.11 + */
    1.12 +
    1.13 +class TwrOnNonResource {
    1.14 +    public static void main(String... args) {
    1.15 +        try(TwrOnNonResource aonr = new TwrOnNonResource()) {
    1.16 +            System.out.println(aonr.toString());
    1.17 +        }
    1.18 +        try(TwrOnNonResource aonr = new TwrOnNonResource()) {
    1.19 +            System.out.println(aonr.toString());
    1.20 +        } finally {;}
    1.21 +        try(TwrOnNonResource aonr = new TwrOnNonResource()) {
    1.22 +            System.out.println(aonr.toString());
    1.23 +        } catch (Exception e) {;}
    1.24 +    }
    1.25 +
    1.26 +    /*
    1.27 +     * A close method, but the class is <em>not</em> Closeable or
    1.28 +     * AutoCloseable.
    1.29 +     */
    1.30 +    public void close() {
    1.31 +        throw new AssertionError("I'm not Closable!");
    1.32 +    }
    1.33 +}

mercurial