test/tools/javac/TryWithResources/BadTwr.java

Mon, 02 Aug 2010 13:35:39 -0700

author
darcy
date
Mon, 02 Aug 2010 13:35:39 -0700
changeset 622
38e2c23309f1
parent 0
959103a6100f
permissions
-rw-r--r--

6971877: Project Coin: improve semantics of suppressed exceptions in try-with-resources
Reviewed-by: jjb

     1 /*
     2  * @test  /nodynamiccopyright/
     3  * @bug 6911256 6964740
     4  * @author Joseph D. Darcy
     5  * @summary Verify bad TWRs don't compile
     6  * @compile/fail -source 6 TwrFlow.java
     7  * @compile/fail/ref=BadTwr.out -XDrawDiagnostics BadTwr.java
     8  */
    10 public class BadTwr implements AutoCloseable {
    11     public static void main(String... args) {
    12         // illegal repeated name
    13         try(BadTwr r1 = new BadTwr(); BadTwr r1 = new BadTwr()) {
    14             System.out.println(r1.toString());
    15         }
    17         // illegal duplicate name of method argument
    18         try(BadTwr args = new BadTwr()) {
    19             System.out.println(args.toString());
    20             final BadTwr thatsIt = new BadTwr();
    21             thatsIt = null;
    22         }
    24         try(BadTwr name = new BadTwr()) {
    25             // illegal duplicate name of enclosing try
    26             try(BadTwr name = new BadTwr()) {
    27                 System.out.println(name.toString());
    28             }
    29         }
    31     }
    33     public void close() {
    34         ;
    35     }
    36 }

mercurial