Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7018392

update URLJarFile.java to use try-with-resources

XMLWordPrintable

    • b132
    • generic
    • generic
    • Verified

      Findbugs has flagged some code in the file

      src/share/classes/sun/net/www/protocol/jar/URLJarFile.java

      as potentially not closing its streams. Specifically, the code
      opens streams 'in' and 'out' and attempts to close them in a finally
      block at line 236:

          } finally {
              if (in != null) {
                  in.close();
              }
              if (out != null) {
                  out.close();
              }
          }

      Unfortunately, if in.close() were to throw an exception, this might
      leave out unclosed. There are a few other similar problems as well.

      This code can be cleaned up using the new Java 7 try-with-resources
      construct. It can also take advantage of the new Files utility method
      for copying from a stream to a file.

            smarks Stuart Marks
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: