test/tools/javac/TryWithResources/TwrOnNonResource.java

Thu, 09 Sep 2010 09:42:45 +0530

author
sundar
date
Thu, 09 Sep 2010 09:42:45 +0530
changeset 678
014cf6234586
parent 609
13354e1abba7
child 840
7f8794f9cc14
permissions
-rw-r--r--

6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
Reviewed-by: jjg

     1 /*
     2  * @test  /nodynamiccopyright/
     3  * @bug 6911256 6964740
     4  * @author Joseph D. Darcy
     5  * @summary Verify invalid TWR block is not accepted.
     6  * @compile/fail -source 6 TwrOnNonResource.java
     7  * @compile/fail/ref=TwrOnNonResource.out -XDrawDiagnostics TwrOnNonResource.java
     8  */
    10 class TwrOnNonResource {
    11     public static void main(String... args) {
    12         try(TwrOnNonResource aonr = new TwrOnNonResource()) {
    13             System.out.println(aonr.toString());
    14         }
    15         try(TwrOnNonResource aonr = new TwrOnNonResource()) {
    16             System.out.println(aonr.toString());
    17         } finally {;}
    18         try(TwrOnNonResource aonr = new TwrOnNonResource()) {
    19             System.out.println(aonr.toString());
    20         } catch (Exception e) {;}
    22         // Also check expression form
    23         TwrOnNonResource aonr = new TwrOnNonResource();
    24         try(aonr) {
    25             System.out.println(aonr.toString());
    26         }
    27         try(aonr) {
    28             System.out.println(aonr.toString());
    29         } finally {;}
    30         try(aonr) {
    31             System.out.println(aonr.toString());
    32         } catch (Exception e) {;}
    33     }
    35     /*
    36      * A close method, but the class is <em>not</em> Closeable or
    37      * AutoCloseable.
    38      */
    39     public void close() {
    40         throw new AssertionError("I'm not Closable!");
    41     }
    42 }

mercurial