test/tools/javac/TryWithResources/ImplicitFinal.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/TryWithResources/ImplicitFinal.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,40 @@
     1.4 +/*
     1.5 + * @test  /nodynamiccopyright/
     1.6 + * @bug 6911256 6964740 6965277 7013420
     1.7 + * @author Maurizio Cimadamore
     1.8 + * @summary Test that resource variables are implicitly final
     1.9 + * @compile/fail/ref=ImplicitFinal.out -XDrawDiagnostics ImplicitFinal.java
    1.10 + */
    1.11 +
    1.12 +import java.io.IOException;
    1.13 +
    1.14 +class ImplicitFinal implements AutoCloseable {
    1.15 +    public static void main(String... args) {
    1.16 +        try(ImplicitFinal r = new ImplicitFinal()) {
    1.17 +            r = null; //disallowed
    1.18 +        } catch (IOException ioe) { // Not reachable
    1.19 +            throw new AssertionError("Shouldn't reach here", ioe);
    1.20 +        }
    1.21 +
    1.22 +        try(@SuppressWarnings("unchecked") ImplicitFinal r1 = new ImplicitFinal()) {
    1.23 +            r1 = null; //disallowed
    1.24 +        } catch (IOException ioe) { // Not reachable
    1.25 +            throw new AssertionError("Shouldn't reach here", ioe);
    1.26 +        }
    1.27 +
    1.28 +        try(final ImplicitFinal r2 = new ImplicitFinal()) {
    1.29 +            r2 = null; //disallowed
    1.30 +        } catch (IOException ioe) { // Not reachable
    1.31 +            throw new AssertionError("Shouldn't reach here", ioe);
    1.32 +        }
    1.33 +
    1.34 +        try(final @SuppressWarnings("unchecked") ImplicitFinal r3 = new ImplicitFinal()) {
    1.35 +            r3 = null; //disallowed
    1.36 +        } catch (IOException ioe) { // Not reachable
    1.37 +            throw new AssertionError("Shouldn't reach here", ioe);
    1.38 +        }
    1.39 +    }
    1.40 +    public void close() throws IOException {
    1.41 +        throw new IOException();
    1.42 +    }
    1.43 +}

mercurial