JDK 9 RFR of JDK-8068948: Update java.base module to use new try-with-resources statement

joe darcy joe.darcy at oracle.com
Wed Jan 14 02:46:59 UTC 2015


Hello,

Earlier in JDK 9, a language change was made so that if a resource for a 
try-with-resources statement is already final or effectively final, a 
new resource variable does *not* need to be declared to manage the variable.

The java.base module should take advantage of this language feature.

I've run an experimental checker for such locations over the base module 
and found one candidate where the new language feature can be used; 
please review this patch for it:

diff -r d873f6a7d16b src/java.base/unix/classes/java/io/FileDescriptor.java
--- a/src/java.base/unix/classes/java/io/FileDescriptor.java    Tue Jan 
13 14:33:54 2015 -0800
+++ b/src/java.base/unix/classes/java/io/FileDescriptor.java    Tue Jan 
13 18:40:54 2015 -0800
@@ -214,7 +214,7 @@
          if (!closed) {
              closed = true;
              IOException ioe = null;
-            try (Closeable c = releaser) {
+            try (releaser) {
                  if (otherParents != null) {
                      for (Closeable referent : otherParents) {
                          try {

The build succeeds with this change and the java.io.FileDescriptor 
regression tests pass.

Thanks,

-Joe



More information about the core-libs-dev mailing list