JDK-7021582 : Project Coin: convert jar and zip util classes and tests to use try-with-resources
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-02-22
  • Updated: 2011-04-27
  • Resolved: 2011-04-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b134Fixed
Related Reports
Relates :  
Relates :  
Description
Findbugs and Jackpot have identified a number of places in the jar and zip implementation classes and tests where try-with-resources can be used. This will fix bugs in certain cases, for example, in src/share/classes/com/sun/java/util/jar/pack/NativeUnpack.java there is the following code (near line 240):

        FileInputStream fis = new FileInputStream(inFile);
        run(fis, jstream, mappedFile);
        fis.close();

If the run() call were to throw an exception, the FileInputStream would be left open. Using try-with-resources the code would be changed to:

        try (FileInputStream fis = new FileInputStream(inFile)) {
            run(fis, jstream, mappedFile);
        }

There are a few dozen similar changes in several places in the library and in the corresponding test code.

Comments
EVALUATION Approximate list of files affected: src/share/classes/com/sun/java/util/jar/pack/BandStructure.java src/share/classes/com/sun/java/util/jar/pack/Driver.java src/share/classes/com/sun/java/util/jar/pack/NativeUnpack.java src/share/classes/com/sun/java/util/jar/pack/PackageReader.java src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java src/share/classes/com/sun/java/util/jar/pack/PackerImpl.java src/share/classes/com/sun/java/util/jar/pack/PropMap.java src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java src/share/classes/com/sun/java/util/jar/pack/Utils.java src/share/classes/java/util/jar/JarFile.java test/java/util/jar/JarEntry/GetMethodsReturnClones.java test/java/util/jar/JarFile/ScanSignedJar.java test/java/util/jar/JarFile/SorryClosed.java test/java/util/zip/Available.java test/java/util/zip/ConstructDeflaterInput.java test/java/util/zip/ConstructInflaterOutput.java test/java/util/zip/DataDescriptor.java test/java/util/zip/FileBuilder.java test/java/util/zip/GZIP/Accordion.java test/java/util/zip/GZIP/GZIPInputStreamRead.java test/java/util/zip/InflateIn_DeflateOut.java test/java/util/zip/InfoZip.java test/java/util/zip/LargeZip.java test/java/util/zip/StoredCRC.java test/java/util/zip/TestEmptyZip.java test/java/util/zip/ZipCoding.java test/java/util/zip/ZipFile/Assortment.java test/java/util/zip/ZipFile/Comment.java test/java/util/zip/ZipFile/CopyJar.java test/java/util/zip/ZipFile/CorruptedZipFiles.java test/java/util/zip/ZipFile/DeleteTempJar.java test/java/util/zip/ZipFile/EnumAfterClose.java test/java/util/zip/ZipFile/GetDirEntry.java test/java/util/zip/ZipFile/LargeZipFile.java test/java/util/zip/ZipFile/ManyEntries.java test/java/util/zip/ZipFile/ManyZipFiles.java test/java/util/zip/ZipFile/ReadAfterClose.java test/java/util/zip/ZipFile/ReadLongZipFileName.java test/java/util/zip/ZipFile/ReadZip.java test/java/util/zip/ZipFile/ShortRead.java test/java/util/zip/zip.java
22-02-2011