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