test/tools/javac/TryWithResources/TwrLint.java

Mon, 28 Feb 2011 13:42:24 -0800

author
jjg
date
Mon, 28 Feb 2011 13:42:24 -0800
changeset 899
67d6b2df47ba
parent 0
959103a6100f
permissions
-rw-r--r--

7022711: compiler crash in try-with-resources
Reviewed-by: mcimadamore

     1 /*
     2  * @test  /nodynamiccopyright/
     3  * @bug 6911256 6964740 6965277 6967065
     4  * @author Joseph D. Darcy
     5  * @summary Check that -Xlint:twr warnings are generated as expected
     6  * @compile/ref=TwrLint.out -Xlint:try,deprecation -XDrawDiagnostics TwrLint.java
     7  */
     9 class TwrLint implements AutoCloseable {
    10     private static void test1() {
    11         try(TwrLint r1 = new TwrLint();
    12             TwrLint r2 = new TwrLint();
    13             TwrLint r3 = new TwrLint()) {
    14             r1.close();   // The resource's close
    15             r2.close(42); // *Not* the resource's close
    16             // r3 not referenced
    17         }
    19     }
    21     @SuppressWarnings("try")
    22     private static void test2() {
    23         try(@SuppressWarnings("deprecation") AutoCloseable r4 =
    24             new DeprecatedAutoCloseable()) {
    25             // r4 not referenced - but no warning is generated because of @SuppressWarnings
    26         } catch(Exception e) {
    27             ;
    28         }
    29     }
    31     /**
    32      * The AutoCloseable method of a resource.
    33      */
    34     @Override
    35     public void close () {
    36         return;
    37     }
    39     /**
    40      * <em>Not</em> the AutoCloseable method of a resource.
    41      */
    42     public void close (int arg) {
    43         return;
    44     }
    45 }
    47 @Deprecated
    48 class DeprecatedAutoCloseable implements AutoCloseable {
    49     public DeprecatedAutoCloseable(){super();}
    51     @Override
    52     public void close () {
    53         return;
    54     }
    55 }

mercurial