author | mcimadamore |
Wed, 26 Oct 2016 15:41:25 +0100 | |
changeset 41856 | 13a056e8f16e |
parent 34565 | 627464b87753 |
permissions | -rw-r--r-- |
34565
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
1 |
/* |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
2 |
* @test /nodynamiccopyright/ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
3 |
* @bug 7196163 |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
4 |
* @summary Twr with different kinds of variables: local, instance, class, array component, parameter |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
5 |
* @compile/fail/ref=TwrVarKinds.out -XDrawDiagnostics TwrVarKinds.java |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
6 |
*/ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
7 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
8 |
public class TwrVarKinds implements AutoCloseable { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
9 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
10 |
final static TwrVarKinds r1 = new TwrVarKinds(); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
11 |
final TwrVarKinds r2 = new TwrVarKinds(); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
12 |
static TwrVarKinds r3 = new TwrVarKinds(); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
13 |
TwrVarKinds r4 = new TwrVarKinds(); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
14 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
15 |
public static void main(String... args) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
16 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
17 |
TwrVarKinds r5 = new TwrVarKinds(); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
18 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
19 |
/* static final field - ok */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
20 |
try (r1) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
21 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
22 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
23 |
/* non-static final field - ok */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
24 |
try (r1.r2) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
25 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
26 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
27 |
/* static non-final field - wrong */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
28 |
try (r3) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
29 |
fail("Static non-final field is not allowed"); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
30 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
31 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
32 |
/* non-static non-final field - wrong */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
33 |
try (r1.r4) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
34 |
fail("Non-static non-final field is not allowed"); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
35 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
36 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
37 |
/* local variable - covered by TwrForVariable1 test */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
38 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
39 |
/* array components - covered by TwrForVariable2 test */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
40 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
41 |
/* method parameter - ok */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
42 |
method(r5); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
43 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
44 |
/* constructor parameter - ok */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
45 |
TwrVarKinds r6 = new TwrVarKinds(r5); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
46 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
47 |
/* lambda parameter - covered by TwrAndLambda */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
48 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
49 |
/* exception parameter - ok */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
50 |
try { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
51 |
throw new ResourceException(); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
52 |
} catch (ResourceException e) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
53 |
try (e) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
54 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
55 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
56 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
57 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
58 |
public TwrVarKinds() { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
59 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
60 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
61 |
public TwrVarKinds(TwrVarKinds r) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
62 |
try (r) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
63 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
64 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
65 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
66 |
static void method(TwrVarKinds r) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
67 |
/* parameter */ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
68 |
try (r) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
69 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
70 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
71 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
72 |
static void fail(String reason) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
73 |
throw new RuntimeException(reason); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
74 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
75 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
76 |
public void close() {} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
77 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
78 |
static class ResourceException extends Exception implements AutoCloseable { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
79 |
public void close() {} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
80 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
81 |
} |