test/tools/javac/TryWithResources/ImplicitFinal.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

aoqi@0 1 /*
aoqi@0 2 * @test /nodynamiccopyright/
aoqi@0 3 * @bug 6911256 6964740 6965277 7013420
aoqi@0 4 * @author Maurizio Cimadamore
aoqi@0 5 * @summary Test that resource variables are implicitly final
aoqi@0 6 * @compile/fail/ref=ImplicitFinal.out -XDrawDiagnostics ImplicitFinal.java
aoqi@0 7 */
aoqi@0 8
aoqi@0 9 import java.io.IOException;
aoqi@0 10
aoqi@0 11 class ImplicitFinal implements AutoCloseable {
aoqi@0 12 public static void main(String... args) {
aoqi@0 13 try(ImplicitFinal r = new ImplicitFinal()) {
aoqi@0 14 r = null; //disallowed
aoqi@0 15 } catch (IOException ioe) { // Not reachable
aoqi@0 16 throw new AssertionError("Shouldn't reach here", ioe);
aoqi@0 17 }
aoqi@0 18
aoqi@0 19 try(@SuppressWarnings("unchecked") ImplicitFinal r1 = new ImplicitFinal()) {
aoqi@0 20 r1 = null; //disallowed
aoqi@0 21 } catch (IOException ioe) { // Not reachable
aoqi@0 22 throw new AssertionError("Shouldn't reach here", ioe);
aoqi@0 23 }
aoqi@0 24
aoqi@0 25 try(final ImplicitFinal r2 = new ImplicitFinal()) {
aoqi@0 26 r2 = null; //disallowed
aoqi@0 27 } catch (IOException ioe) { // Not reachable
aoqi@0 28 throw new AssertionError("Shouldn't reach here", ioe);
aoqi@0 29 }
aoqi@0 30
aoqi@0 31 try(final @SuppressWarnings("unchecked") ImplicitFinal r3 = new ImplicitFinal()) {
aoqi@0 32 r3 = null; //disallowed
aoqi@0 33 } catch (IOException ioe) { // Not reachable
aoqi@0 34 throw new AssertionError("Shouldn't reach here", ioe);
aoqi@0 35 }
aoqi@0 36 }
aoqi@0 37 public void close() throws IOException {
aoqi@0 38 throw new IOException();
aoqi@0 39 }
aoqi@0 40 }

mercurial