test/tools/javac/TryWithResources/ResourceNameConflict.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/TryWithResources/ResourceNameConflict.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,36 @@
     1.4 +/*
     1.5 + * @test  /nodynamiccopyright/
     1.6 + * @bug 8025113
     1.7 + * @author sogoel
     1.8 + * @summary Resource var cannot have same name as local variable
     1.9 + * @compile/fail/ref=ResourceNameConflict.out -XDrawDiagnostics ResourceNameConflict.java
    1.10 + */
    1.11 +
    1.12 +/**
    1.13 + * Test methods and their description
    1.14 + * test1() - negative test - local variable used as test resource
    1.15 + * test2() - negative test - test resource already defined in an enclosing for statement
    1.16 + */
    1.17 +
    1.18 +public class ResourceNameConflict implements AutoCloseable {
    1.19 +
    1.20 +    static final String str = "asdf";
    1.21 +
    1.22 +    void test1() {
    1.23 +        String tr = "A resource spec var cannot have same name as local var.";
    1.24 +        try (ResourceNameConflict tr = new ResourceNameConflict()) {
    1.25 +        }
    1.26 +    }
    1.27 +
    1.28 +    void test2(String... strArray) {
    1.29 +        for (String str : strArray) {
    1.30 +            try (ResourceNameConflict str = new ResourceNameConflict()) {
    1.31 +            }
    1.32 +        }
    1.33 +    }
    1.34 +
    1.35 +    @Override
    1.36 +    public void close() {
    1.37 +    }
    1.38 +}
    1.39 +

mercurial