aoqi@0: /* aoqi@0: * @test /nodynamiccopyright/ aoqi@0: * @bug 6911256 6964740 6965277 6967065 aoqi@0: * @author Joseph D. Darcy aoqi@0: * @summary Check that -Xlint:twr warnings are generated as expected aoqi@0: * @compile/ref=TwrLint.out -Xlint:try,deprecation -XDrawDiagnostics TwrLint.java aoqi@0: */ aoqi@0: aoqi@0: class TwrLint implements AutoCloseable { aoqi@0: private static void test1() { aoqi@0: try(TwrLint r1 = new TwrLint(); aoqi@0: TwrLint r2 = new TwrLint(); aoqi@0: TwrLint r3 = new TwrLint()) { aoqi@0: r1.close(); // The resource's close aoqi@0: r2.close(42); // *Not* the resource's close aoqi@0: // r3 not referenced aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: @SuppressWarnings("try") aoqi@0: private static void test2() { aoqi@0: try(@SuppressWarnings("deprecation") AutoCloseable r4 = aoqi@0: new DeprecatedAutoCloseable()) { aoqi@0: // r4 not referenced - but no warning is generated because of @SuppressWarnings aoqi@0: } catch(Exception e) { aoqi@0: ; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * The AutoCloseable method of a resource. aoqi@0: */ aoqi@0: @Override aoqi@0: public void close () { aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Not the AutoCloseable method of a resource. aoqi@0: */ aoqi@0: public void close (int arg) { aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: @Deprecated aoqi@0: class DeprecatedAutoCloseable implements AutoCloseable { aoqi@0: public DeprecatedAutoCloseable(){super();} aoqi@0: aoqi@0: @Override aoqi@0: public void close () { aoqi@0: return; aoqi@0: } aoqi@0: }