langtools/test/tools/javac/TryWithResources/ImplicitFinal.java
author sogoel
Thu, 05 Jun 2014 10:57:10 -0700
changeset 24797 850ebd4d80a7
parent 8224 8f18e1622660
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:
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     1
/*
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     2
 * @test  /nodynamiccopyright/
8224
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
     3
 * @bug 6911256 6964740 6965277 7013420
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     4
 * @author Maurizio Cimadamore
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     5
 * @summary Test that resource variables are implicitly final
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     6
 * @compile/fail/ref=ImplicitFinal.out -XDrawDiagnostics ImplicitFinal.java
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     7
 */
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     8
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     9
import java.io.IOException;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    10
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    11
class ImplicitFinal implements AutoCloseable {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    12
    public static void main(String... args) {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    13
        try(ImplicitFinal r = new ImplicitFinal()) {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    14
            r = null; //disallowed
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    15
        } catch (IOException ioe) { // Not reachable
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    16
            throw new AssertionError("Shouldn't reach here", ioe);
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    17
        }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    18
8224
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    19
        try(@SuppressWarnings("unchecked") ImplicitFinal r1 = new ImplicitFinal()) {
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    20
            r1 = null; //disallowed
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    21
        } catch (IOException ioe) { // Not reachable
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    22
            throw new AssertionError("Shouldn't reach here", ioe);
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    23
        }
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    24
8224
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    25
        try(final ImplicitFinal r2 = new ImplicitFinal()) {
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    26
            r2 = null; //disallowed
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    27
        } catch (IOException ioe) { // Not reachable
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    28
            throw new AssertionError("Shouldn't reach here", ioe);
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    29
        }
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    30
8224
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    31
        try(final @SuppressWarnings("unchecked") ImplicitFinal r3 = new ImplicitFinal()) {
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    32
            r3 = null; //disallowed
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    33
        } catch (IOException ioe) { // Not reachable
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    34
            throw new AssertionError("Shouldn't reach here", ioe);
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    35
        }
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    36
    }
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    37
    public void close() throws IOException {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    38
        throw new IOException();
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    39
    }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    40
}