aoqi@0: /* aoqi@0: * @test /nodynamiccopyright/ aoqi@0: * @bug 8025113 aoqi@0: * @author sogoel aoqi@0: * @summary Redeclaration of resource variables aoqi@0: * @compile/fail/ref=ResourceRedecl.out -XDrawDiagnostics ResourceRedecl.java aoqi@0: */ aoqi@0: aoqi@0: import java.io.*; aoqi@0: aoqi@0: public class ResourceRedecl { aoqi@0: aoqi@0: public void test() { aoqi@0: // compiler error if name of an exception param is redeclared within the Block of the catch clause as a local var; aoqi@0: // or as an exception param of a catch clause in a try statement; aoqi@0: // or as a resource in a try-with-resources statement aoqi@0: try { aoqi@0: } catch (Exception exParam1) { aoqi@0: Object exParam1 = new Object(); aoqi@0: try (java.io.FileInputStream exParam1 = new java.io.FileInputStream("foo.txt")) { aoqi@0: Object exParam1 = new Object(); aoqi@0: } catch (IOException exParam1) { aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // compiler error if resource is redeclared within the try Block as a local var aoqi@0: // or as an exception param of a catch clause in a try statement aoqi@0: try (java.io.FileInputStream exParam2 = new java.io.FileInputStream("bar.txt")) { aoqi@0: Object exParam2 = new Object(); aoqi@0: try (BufferedReader br = new BufferedReader(new FileReader("zee.txt"))) { aoqi@0: } catch (IOException exParam2) { aoqi@0: } aoqi@0: } catch (Exception ex) { aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: