< prev index next >

test/langtools/tools/javac/TryWithResources/WeirdTwr.java

Print this page


   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 6911256 6964740
   4  * @author Joseph D. Darcy
   5  * @summary Strange TWRs
   6  * @compile/fail/ref=WeirdTwr.out -XDrawDiagnostics -source 6 WeirdTwr.java
   7  * @compile WeirdTwr.java
   8  * @run main WeirdTwr
   9  */
  10 
  11 public class WeirdTwr implements AutoCloseable {
  12     private static int closeCount = 0;
  13     public static void main(String... args) {
  14         try(WeirdTwr r1 = new WeirdTwr(); WeirdTwr r2 = r1) {
  15             if (r1 != r2)
  16                 throw new RuntimeException("Unexpected inequality.");
  17         }
  18         if (closeCount != 2)
  19             throw new RuntimeException("bad closeCount" + closeCount);
  20     }
  21 
  22     public void close() {
  23         closeCount++;
  24     }
  25 }
   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 6911256 6964740
   4  * @author Joseph D. Darcy
   5  * @summary Strange TWRs

   6  * @compile WeirdTwr.java
   7  * @run main WeirdTwr
   8  */
   9 
  10 public class WeirdTwr implements AutoCloseable {
  11     private static int closeCount = 0;
  12     public static void main(String... args) {
  13         try(WeirdTwr r1 = new WeirdTwr(); WeirdTwr r2 = r1) {
  14             if (r1 != r2)
  15                 throw new RuntimeException("Unexpected inequality.");
  16         }
  17         if (closeCount != 2)
  18             throw new RuntimeException("bad closeCount" + closeCount);
  19     }
  20 
  21     public void close() {
  22         closeCount++;
  23     }
  24 }
< prev index next >