test/tools/javac/TryWithResources/ResourceOutsideTry.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/TryWithResources/ResourceOutsideTry.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,23 @@
     1.4 +/*
     1.5 + * @test  /nodynamiccopyright/
     1.6 + * @bug 6911256 6964740 6965277
     1.7 + * @author Maurizio Cimadamore
     1.8 + * @summary Check that resource variable is not accessible from catch/finally clause
     1.9 + * @compile/fail/ref=ResourceOutsideTry.out -XDrawDiagnostics ResourceOutsideTry.java
    1.10 + */
    1.11 +
    1.12 +class ResourceOutsideTry {
    1.13 +    void test() {
    1.14 +        try(MyResource c = new MyResource()) {
    1.15 +        //do something
    1.16 +        } catch (Exception e) {
    1.17 +            c.test();
    1.18 +        } finally {
    1.19 +            c.test();
    1.20 +        }
    1.21 +    }
    1.22 +    static class MyResource implements AutoCloseable {
    1.23 +        public void close() throws Exception {}
    1.24 +        void test() {}
    1.25 +    }
    1.26 +}

mercurial