langtools/test/tools/javac/TryWithResources/ResourceRedecl.java
author sogoel
Thu, 05 Jun 2014 10:57:10 -0700
changeset 24797 850ebd4d80a7
parent 21714 f5b7edec4304
permissions -rw-r--r--
8044072: Group 2: create .out files for OverrideChecks tests in tools/javac dir Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21714
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
     1
/*
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
     2
 * @test    /nodynamiccopyright/
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
     3
 * @bug     8025113
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
     4
 * @author  sogoel
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
     5
 * @summary Redeclaration of resource variables
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
     6
 * @compile/fail/ref=ResourceRedecl.out -XDrawDiagnostics ResourceRedecl.java
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
     7
 */
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
     8
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
     9
import java.io.*;
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    10
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    11
public class ResourceRedecl {
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    12
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    13
    public void test() {
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    14
        // compiler error if name of an exception param is redeclared within the Block of the catch clause as a local var;
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    15
        // or as an exception param of a catch clause in a try statement;
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    16
        // or as a resource in a try-with-resources statement
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    17
        try {
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    18
        } catch (Exception exParam1) {
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    19
            Object exParam1 = new Object();
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    20
            try (java.io.FileInputStream exParam1 = new java.io.FileInputStream("foo.txt")) {
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    21
                Object exParam1 = new Object();
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    22
            } catch (IOException exParam1) {
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    23
            }
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    24
        }
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    25
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    26
        // compiler error if resource is redeclared within the try Block as a local var
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    27
        // or as an exception param of a catch clause in a try statement
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    28
        try (java.io.FileInputStream exParam2 = new java.io.FileInputStream("bar.txt")) {
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    29
            Object exParam2 = new Object();
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    30
            try (BufferedReader br = new BufferedReader(new FileReader("zee.txt"))) {
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    31
            } catch (IOException exParam2) {
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    32
            }
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    33
        } catch (Exception ex) {
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    34
        }
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    35
    }
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    36
}
f5b7edec4304 8025113: Convert 7 tools TryWithResources tests to jtreg format
sogoel
parents:
diff changeset
    37