test/tools/javac/TryWithResources/ResourceNameConflict.java

Wed, 13 Aug 2014 14:50:00 -0700

author
katleman
date
Wed, 13 Aug 2014 14:50:00 -0700
changeset 2549
0b6cc4ea670f
parent 0
959103a6100f
permissions
-rw-r--r--

Added tag jdk8u40-b01 for changeset bf89a471779d

     1 /*
     2  * @test  /nodynamiccopyright/
     3  * @bug 8025113
     4  * @author sogoel
     5  * @summary Resource var cannot have same name as local variable
     6  * @compile/fail/ref=ResourceNameConflict.out -XDrawDiagnostics ResourceNameConflict.java
     7  */
     9 /**
    10  * Test methods and their description
    11  * test1() - negative test - local variable used as test resource
    12  * test2() - negative test - test resource already defined in an enclosing for statement
    13  */
    15 public class ResourceNameConflict implements AutoCloseable {
    17     static final String str = "asdf";
    19     void test1() {
    20         String tr = "A resource spec var cannot have same name as local var.";
    21         try (ResourceNameConflict tr = new ResourceNameConflict()) {
    22         }
    23     }
    25     void test2(String... strArray) {
    26         for (String str : strArray) {
    27             try (ResourceNameConflict str = new ResourceNameConflict()) {
    28             }
    29         }
    30     }
    32     @Override
    33     public void close() {
    34     }
    35 }

mercurial