author | jlahoda |
Wed, 09 Dec 2015 14:26:56 +0100 | |
changeset 34565 | 627464b87753 |
parent 27844 | 8b5d79870a2f |
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 an improper combination of modifiers and variable is rejected |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
4 |
* in an operand to try-with-resources |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
5 |
* @compile/fail/ref=TwrForVariable2.out -XDrawDiagnostics -Xlint:-options TwrForVariable2.java |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
6 |
*/ |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
7 |
public class TwrForVariable2 implements AutoCloseable { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
8 |
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
|
9 |
TwrForVariable2 v = new TwrForVariable2(); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
10 |
TwrForVariable3[] v2 = new TwrForVariable3[1]; |
34565
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
27844
diff
changeset
|
11 |
TwrForVariable3[][] v3 = new TwrForVariable3[1][1]; |
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
12 |
|
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
13 |
try (final v) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
14 |
fail("no modifiers before variables"); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
15 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
16 |
try (@Deprecated v) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
17 |
fail("no annotations before variables"); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
18 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
19 |
try (v;;) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
20 |
fail("illegal double semicolon"); |
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 |
try ((v)) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
23 |
fail("parentheses not allowed"); |
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 |
try (v2[0]) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
26 |
fail("array access not allowed"); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
27 |
} |
34565
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
27844
diff
changeset
|
28 |
try (v3[0][0]) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
27844
diff
changeset
|
29 |
fail("array access not allowed"); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
27844
diff
changeset
|
30 |
} |
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
31 |
try (args.length == 0 ? v : v) { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
32 |
fail("general expressions not allowed"); |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
33 |
} |
34565
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
27844
diff
changeset
|
34 |
try ((TwrForVariable2)null) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
27844
diff
changeset
|
35 |
fail("null as variable is not allowed"); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
27844
diff
changeset
|
36 |
} |
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
37 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
38 |
|
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
39 |
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
|
40 |
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
|
41 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
42 |
|
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
43 |
public void close() { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
44 |
} |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
45 |
|
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
diff
changeset
|
46 |
} |