--- /dev/null 2009-07-06 20:02:10.000000000 -0700 +++ new/test/tools/javac/AutomaticResourceManagement/ArmFlow.java 2010-07-05 23:56:47.000000000 -0700 @@ -0,0 +1,40 @@ +/* + * @test /nodynamiccopyright/ + * @bug 6911256 6964740 + * @author Joseph D. Darcy + * @summary Test exception analysis of ARM blocks + * @compile/fail -source 6 ArmFlow.java + * @compile/fail/ref=ArmFlow.out -XDrawDiagnostics ArmFlow.java + */ + +import java.io.IOException; +public class ArmFlow implements AutoCloseable { + public static void main(String... args) { + try(ArmFlow armflow = new ArmFlow()) { + System.out.println(armflow.toString()); + } catch (IOException ioe) { // Not reachable + throw new AssertionError("Shouldn't reach here", ioe); + } + // CustomCloseException should be caught or added to throws clause + + // Also check behavior on a resource expression rather than a + // declaration. + ArmFlow armflowexpr = new ArmFlow(); + try(armflowexpr) { + System.out.println(armflowexpr.toString()); + } catch (IOException ioe) { // Not reachable + throw new AssertionError("Shouldn't reach here", ioe); + } + // CustomCloseException should be caught or added to throws clause + } + + /* + * A close method, but the class is not Closeable or + * AutoCloseable. + */ + public void close() throws CustomCloseException { + throw new CustomCloseException(); + } +} + +class CustomCloseException extends Exception {}