test/tools/javac/TryWithResources/ResourceRedecl.java

Mon, 26 Oct 2015 13:23:30 -0700

author
asaha
date
Mon, 26 Oct 2015 13:23:30 -0700
changeset 2999
683b3e7e05a7
parent 0
959103a6100f
permissions
-rw-r--r--

Added tag jdk8u76-b00 for changeset 10ffafaf5340

     1 /*
     2  * @test    /nodynamiccopyright/
     3  * @bug     8025113
     4  * @author  sogoel
     5  * @summary Redeclaration of resource variables
     6  * @compile/fail/ref=ResourceRedecl.out -XDrawDiagnostics ResourceRedecl.java
     7  */
     9 import java.io.*;
    11 public class ResourceRedecl {
    13     public void test() {
    14         // compiler error if name of an exception param is redeclared within the Block of the catch clause as a local var;
    15         // or as an exception param of a catch clause in a try statement;
    16         // or as a resource in a try-with-resources statement
    17         try {
    18         } catch (Exception exParam1) {
    19             Object exParam1 = new Object();
    20             try (java.io.FileInputStream exParam1 = new java.io.FileInputStream("foo.txt")) {
    21                 Object exParam1 = new Object();
    22             } catch (IOException exParam1) {
    23             }
    24         }
    26         // compiler error if resource is redeclared within the try Block as a local var
    27         // or as an exception param of a catch clause in a try statement
    28         try (java.io.FileInputStream exParam2 = new java.io.FileInputStream("bar.txt")) {
    29             Object exParam2 = new Object();
    30             try (BufferedReader br = new BufferedReader(new FileReader("zee.txt"))) {
    31             } catch (IOException exParam2) {
    32             }
    33         } catch (Exception ex) {
    34         }
    35     }
    36 }

mercurial