/* * @test /nodynamiccopyright/ * @bug 7196163 * @summary Twr with resource variables declared as anonymous class instance * @compile/fail/ref=TwrAndAnonymousClass.out -XDrawDiagnostics TwrAndAnonymousClass.java */ public class TwrAndAnonymousClass { public static void main(String... args) { // positive: anonymous class implementing AutoCloseable as variable in twr AutoCloseable r1 = new AutoCloseable() { public void close() { }; }; try (r1) { } catch (Exception e) {} // positive: declaration of anonymous class implementing AutoCloseable in twr try (AutoCloseable r2 = new AutoCloseable() { public void close() { }; };) { } catch (Exception e) {} // negative: not AutoCloseable anonymous class as variable in twr Object o1 = new Object() { public void close() { }; }; try (o1) { } catch (Exception e) {} // negative: declaration of not AutoCloseable anonymous class in twr try (Object o2 = new Object() { public void close() { }; };) { } catch (Exception e) {} } }