1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/TryWithResources/TwrOnNonResource.java Fri Jul 16 19:35:24 2010 -0700 1.3 @@ -0,0 +1,42 @@ 1.4 +/* 1.5 + * @test /nodynamiccopyright/ 1.6 + * @bug 6911256 6964740 1.7 + * @author Joseph D. Darcy 1.8 + * @summary Verify invalid TWR block is not accepted. 1.9 + * @compile/fail -source 6 TwrOnNonResource.java 1.10 + * @compile/fail/ref=TwrOnNonResource.out -XDrawDiagnostics TwrOnNonResource.java 1.11 + */ 1.12 + 1.13 +class TwrOnNonResource { 1.14 + public static void main(String... args) { 1.15 + try(TwrOnNonResource aonr = new TwrOnNonResource()) { 1.16 + System.out.println(aonr.toString()); 1.17 + } 1.18 + try(TwrOnNonResource aonr = new TwrOnNonResource()) { 1.19 + System.out.println(aonr.toString()); 1.20 + } finally {;} 1.21 + try(TwrOnNonResource aonr = new TwrOnNonResource()) { 1.22 + System.out.println(aonr.toString()); 1.23 + } catch (Exception e) {;} 1.24 + 1.25 + // Also check expression form 1.26 + TwrOnNonResource aonr = new TwrOnNonResource(); 1.27 + try(aonr) { 1.28 + System.out.println(aonr.toString()); 1.29 + } 1.30 + try(aonr) { 1.31 + System.out.println(aonr.toString()); 1.32 + } finally {;} 1.33 + try(aonr) { 1.34 + System.out.println(aonr.toString()); 1.35 + } catch (Exception e) {;} 1.36 + } 1.37 + 1.38 + /* 1.39 + * A close method, but the class is <em>not</em> Closeable or 1.40 + * AutoCloseable. 1.41 + */ 1.42 + public void close() { 1.43 + throw new AssertionError("I'm not Closable!"); 1.44 + } 1.45 +}