langtools/test/tools/javac/TryWithResources/ImplicitFinal.java
author mcimadamore
Mon, 24 Jan 2011 15:44:51 +0000
changeset 8045 df2ca0edfbaa
parent 6148 3a8158299c51
child 8224 8f18e1622660
permissions -rw-r--r--
6968793: issues with diagnostics Summary: several diagnostic improvements 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/
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     3
 * @bug 6911256 6964740 6965277
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
    }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    19
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    20
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    21
     // A close method, but the class is <em>not</em> Closeable or
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    22
     // AutoCloseable.
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    23
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    24
    public void close() throws IOException {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    25
        throw new IOException();
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    26
    }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    27
}