1 /* 2 * @test /nodynamiccopyright/ 3 * @bug 7196163 4 * @summary Twr with resource variables declared as anonymous class instance 5 * @compile/fail/ref=TwrAndAnonymousClass.out -XDrawDiagnostics TwrAndAnonymousClass.java 6 */ 7 8 public class TwrAndAnonymousClass { 9 10 public static void main(String... args) { 11 12 // positive: anonymous class implementing AutoCloseable as variable in twr 13 AutoCloseable r1 = new AutoCloseable() { 14 public void close() { }; 15 }; 16 try (r1) { 17 } catch (Exception e) {} 18 19 // positive: declaration of anonymous class implementing AutoCloseable in twr 20 try (AutoCloseable r2 = new AutoCloseable() { public void close() { }; };) { 21 } catch (Exception e) {} 22 23 // negative: not AutoCloseable anonymous class as variable in twr 24 Object o1 = new Object() { 25 public void close() { }; 26 }; 27 try (o1) { 28 } catch (Exception e) {} 29 30 // negative: declaration of not AutoCloseable anonymous class in twr 31 try (Object o2 = new Object() { public void close() { }; };) { 32 } catch (Exception e) {} 33 } 34 }