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

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

mercurial