1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 7196163
   4  * @summary Twr with different kinds of variables: local, instance, class, parameter
   5  * @compile/fail/ref=TwrVarKinds.out -XDrawDiagnostics TwrVarKinds.java
   6  */
   7 
   8 public class TwrVarKinds implements AutoCloseable {
   9 
  10     final static TwrVarKinds r1 = new TwrVarKinds();
  11     final TwrVarKinds r2 = new TwrVarKinds();
  12     static TwrVarKinds r3 = new TwrVarKinds();
  13     TwrVarKinds r4 = new TwrVarKinds();
  14 
  15     public static void main(String... args) {
  16 
  17         TwrVarKinds r5 = new TwrVarKinds();
  18 
  19         /* static final field - ok */
  20         try (r1) {
  21         }
  22 
  23         /* non-static final field - ok */
  24         try (r1.r2) {
  25         }
  26 
  27         /* static non-final field - wrong */
  28         try (r3) {
  29         }
  30 
  31         /* non-static non-final field - wrong */
  32         try (r1.r4) {
  33         }
  34 
  35         /* local variable - ok */
  36         try (r5) {
  37         }
  38 
  39         /* method parameter - ok */
  40         method(r5);
  41 
  42         /* constructor parameter - ok */
  43         TwrVarKinds r6 = new TwrVarKinds(r5);
  44 
  45         /* lambda parameter - ok */
  46         I i = (x) -> { try (x) {} };
  47         i.m(r5);
  48 
  49         /* exception parameter - ok */
  50         try {
  51             throw new ResourceException();
  52         } catch (ResourceException e) {
  53             try (e) {
  54             }
  55         }
  56     }
  57 
  58     public TwrVarKinds() {
  59     }
  60 
  61     public TwrVarKinds(TwrVarKinds r) {
  62         try (r) {
  63         }
  64     }
  65 
  66     static void method(TwrVarKinds r) {
  67         /* parameter */
  68         try (r) {
  69         }
  70     }
  71 
  72     public void close() {}
  73 
  74     static interface I {
  75         public void m(TwrVarKinds r);
  76     }
  77 
  78     static class ResourceException extends Exception implements AutoCloseable {
  79         public void close() {}
  80     }
  81 }