langtools/test/tools/javac/TryWithResources/TwrFlow.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 8224 8f18e1622660
permissions -rw-r--r--
8074432: Move jdeps and javap to jdk.jdeps module Reviewed-by: jjg, alanb, erikj
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 7013420
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     4
 * @author Joseph D. Darcy
8224
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
     5
 * @summary Test exception analysis of try-with-resources blocks
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
     6
 * @compile/fail/ref=TwrFlow.out -XDrawDiagnostics TwrFlow.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
public class TwrFlow implements AutoCloseable {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    11
    public static void main(String... args) {
8224
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    12
        try(TwrFlow twrFlow = new TwrFlow()) {
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 6148
diff changeset
    13
            System.out.println(twrFlow.toString());
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    14
        } catch (IOException ioe) { // Not reachable
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    15
            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
    16
        }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    17
        // CustomCloseException should be caught or added to throws clause
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 CustomCloseException {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    25
        throw new CustomCloseException();
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
}
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    28
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
diff changeset
    29
class CustomCloseException extends Exception {}