test/tools/javac/TryWithResources/ResourceRedecl.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/TryWithResources/ResourceRedecl.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,37 @@
     1.4 +/*
     1.5 + * @test    /nodynamiccopyright/
     1.6 + * @bug     8025113
     1.7 + * @author  sogoel
     1.8 + * @summary Redeclaration of resource variables
     1.9 + * @compile/fail/ref=ResourceRedecl.out -XDrawDiagnostics ResourceRedecl.java
    1.10 + */
    1.11 +
    1.12 +import java.io.*;
    1.13 +
    1.14 +public class ResourceRedecl {
    1.15 +
    1.16 +    public void test() {
    1.17 +        // compiler error if name of an exception param is redeclared within the Block of the catch clause as a local var;
    1.18 +        // or as an exception param of a catch clause in a try statement;
    1.19 +        // or as a resource in a try-with-resources statement
    1.20 +        try {
    1.21 +        } catch (Exception exParam1) {
    1.22 +            Object exParam1 = new Object();
    1.23 +            try (java.io.FileInputStream exParam1 = new java.io.FileInputStream("foo.txt")) {
    1.24 +                Object exParam1 = new Object();
    1.25 +            } catch (IOException exParam1) {
    1.26 +            }
    1.27 +        }
    1.28 +
    1.29 +        // compiler error if resource is redeclared within the try Block as a local var
    1.30 +        // or as an exception param of a catch clause in a try statement
    1.31 +        try (java.io.FileInputStream exParam2 = new java.io.FileInputStream("bar.txt")) {
    1.32 +            Object exParam2 = new Object();
    1.33 +            try (BufferedReader br = new BufferedReader(new FileReader("zee.txt"))) {
    1.34 +            } catch (IOException exParam2) {
    1.35 +            }
    1.36 +        } catch (Exception ex) {
    1.37 +        }
    1.38 +    }
    1.39 +}
    1.40 +

mercurial