author | mchung |
Wed, 27 May 2015 13:25:18 -0700 | |
changeset 30846 | 2b3f379840f0 |
parent 27844 | 8b5d79870a2f |
child 34565 | 627464b87753 |
permissions | -rw-r--r-- |
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
1 |
/* @test /nodynamiccopyright/ |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
2 |
* @bug 7196163 |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
3 |
* @summary Verify that improper expressions used as an operand to try-with-resources are rejected. |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
4 |
* @compile/fail/ref=TwrForVariable3.out -XDrawDiagnostics -Xlint:-options TwrForVariable3.java |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
5 |
*/ |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
6 |
public class TwrForVariable3 implements AutoCloseable { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
7 |
public static void main(String... args) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
8 |
TwrForVariable3 v1 = new TwrForVariable3(); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
9 |
Object v2 = new Object(); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
10 |
|
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
11 |
try (v2) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
12 |
fail("no an AutoCloseable"); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
13 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
14 |
try (java.lang.Object) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
15 |
fail("not a variable access"); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
16 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
17 |
try (java.lang) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
18 |
fail("not a variable access"); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
19 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
20 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
21 |
|
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
22 |
static void fail(String reason) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
23 |
throw new RuntimeException(reason); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
24 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
25 |
|
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
26 |
public void close() { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
27 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
28 |
|
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
29 |
} |