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