1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
/*
* @test /nodynamiccopyright/
* @bug 6911256 6964740 6965277 6967065
* @author Joseph D. Darcy
* @summary Check that -Xlint:twr warnings are generated as expected
* @compile/ref=TwrLint.out -Xlint:try,deprecation -XDrawDiagnostics TwrLint.java
*/
class TwrLint implements AutoCloseable {
private static void test1() {
try(TwrLint r1 = new TwrLint();
TwrLint r2 = new TwrLint();
TwrLint r3 = new TwrLint()) {
r1.close(); // The resource's close
r2.close(42); // *Not* the resource's close
// r3 not referenced
}
}
@SuppressWarnings("try")
private static void test2() {
try(@SuppressWarnings("deprecation") AutoCloseable r4 =
new DeprecatedAutoCloseable()) {
// r4 not referenced - but no warning is generated because of @SuppressWarnings
} catch(Exception e) {
;
}
}
/**
* The AutoCloseable method of a resource.
*/
@Override
public void close () {
return;
}
/**
* <em>Not</em> the AutoCloseable method of a resource.
*/
public void close (int arg) {
return;
}
}
@Deprecated
class DeprecatedAutoCloseable implements AutoCloseable {
public DeprecatedAutoCloseable(){super();}
@Override
public void close () {
return;
}
}
|