test/tools/javac/TryWithResources/ImplicitFinal.java

changeset 840
7f8794f9cc14
parent 609
13354e1abba7
child 2525
2eb010b6cb22
equal deleted inserted replaced
839:a8437c34fdc7 840:7f8794f9cc14
1 /* 1 /*
2 * @test /nodynamiccopyright/ 2 * @test /nodynamiccopyright/
3 * @bug 6911256 6964740 6965277 3 * @bug 6911256 6964740 6965277 7013420
4 * @author Maurizio Cimadamore 4 * @author Maurizio Cimadamore
5 * @summary Test that resource variables are implicitly final 5 * @summary Test that resource variables are implicitly final
6 * @compile/fail/ref=ImplicitFinal.out -XDrawDiagnostics ImplicitFinal.java 6 * @compile/fail/ref=ImplicitFinal.out -XDrawDiagnostics ImplicitFinal.java
7 */ 7 */
8 8
13 try(ImplicitFinal r = new ImplicitFinal()) { 13 try(ImplicitFinal r = new ImplicitFinal()) {
14 r = null; //disallowed 14 r = null; //disallowed
15 } catch (IOException ioe) { // Not reachable 15 } catch (IOException ioe) { // Not reachable
16 throw new AssertionError("Shouldn't reach here", ioe); 16 throw new AssertionError("Shouldn't reach here", ioe);
17 } 17 }
18
19 try(@SuppressWarnings("unchecked") ImplicitFinal r1 = new ImplicitFinal()) {
20 r1 = null; //disallowed
21 } catch (IOException ioe) { // Not reachable
22 throw new AssertionError("Shouldn't reach here", ioe);
23 }
24
25 try(final ImplicitFinal r2 = new ImplicitFinal()) {
26 r2 = null; //disallowed
27 } catch (IOException ioe) { // Not reachable
28 throw new AssertionError("Shouldn't reach here", ioe);
29 }
30
31 try(final @SuppressWarnings("unchecked") ImplicitFinal r3 = new ImplicitFinal()) {
32 r3 = null; //disallowed
33 } catch (IOException ioe) { // Not reachable
34 throw new AssertionError("Shouldn't reach here", ioe);
35 }
18 } 36 }
19
20
21 // A close method, but the class is <em>not</em> Closeable or
22 // AutoCloseable.
23
24 public void close() throws IOException { 37 public void close() throws IOException {
25 throw new IOException(); 38 throw new IOException();
26 } 39 }
27 } 40 }

mercurial