Jan Lahoda a2b0a2413e 7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
Allowing final variables as operands to try-with-resources; also reviewed by Sergei Pikalev.

Reviewed-by: darcy, mcimadamore, vromero
2014-11-19 13:46:04 +01:00

40 lines
1.1 KiB
Java

/* @test /nodynamiccopyright/
* @bug 7196163
* @summary Verify that an improper combination of modifiers and variable is rejected
* in an operand to try-with-resources
* @compile/fail/ref=TwrForVariable2.out -XDrawDiagnostics -Xlint:-options TwrForVariable2.java
*/
public class TwrForVariable2 implements AutoCloseable {
public static void main(String... args) {
TwrForVariable2 v = new TwrForVariable2();
TwrForVariable3[] v2 = new TwrForVariable3[1];
try (final v) {
fail("no modifiers before variables");
}
try (@Deprecated v) {
fail("no annotations before variables");
}
try (v;;) {
fail("illegal double semicolon");
}
try ((v)) {
fail("parentheses not allowed");
}
try (v2[0]) {
fail("array access not allowed");
}
try (args.length == 0 ? v : v) {
fail("general expressions not allowed");
}
}
static void fail(String reason) {
throw new RuntimeException(reason);
}
public void close() {
}
}