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

JarFile::getInputStream can fail with NPE accessing ze.getName()

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 19
    • core-libs
    • None
    • behavioral
    • minimal
    • Hide
      The javadoc has been updated to explicitly document longstanding behavior for unsigned jar/zip files and the implementation is updated to treat signed jar/zip files the same way in that circumstance.

      Prior to this change, in the case of a signed jar file, a unexpected exception was thrown. This has been corrected so that null is returned to be inline with what happens in the case of a non-signed(or unverified) jar and zip file.
      Show
      The javadoc has been updated to explicitly document longstanding behavior for unsigned jar/zip files and the implementation is updated to treat signed jar/zip files the same way in that circumstance. Prior to this change, in the case of a signed jar file, a unexpected exception was thrown. This has been corrected so that null is returned to be inline with what happens in the case of a non-signed(or unverified) jar and zip file.
    • Other
    • SE

    Description

      Summary

      Clarify the javadoc for ZipFile::getInputStream and JarFile::getInputStream to indicate that null is returned for the InputStream if the specified ZipEntry does not exist within the Jar/Zip file

      Problem

      The javadoc never defined the behavior when the specified Zip/JarEntry does not exist in the Zip/Jar

      Solution

      Clarify the javadoc to indicate the longstanding behavior

      Specification

      The javadoc for ZipFile::getInputStream and JarFile::getInputStream will be modified to indicate a null will be returned when the ZipEntry does not exist within the Jar/Zip file:

       cat ZipDiffs.txt 
      diff --git a/src/java.base/share/classes/java/util/jar/JarFile.java b/src/java.base/share/classes/java/util/jar/JarFile.java
      index 050e93aa48b..b014c18f466 100644
      --- a/src/java.base/share/classes/java/util/jar/JarFile.java
      +++ b/src/java.base/share/classes/java/util/jar/JarFile.java
      @@ -826,7 +826,8 @@ public class JarFile extends ZipFile {
            * zip file entry.
            * @param ze the zip file entry
            * @return an input stream for reading the contents of the specified
      -     *         zip file entry
      +     *         zip file entry or null if the zip file entry does not exist
      +     *         within the jar file
            * @throws ZipException if a zip file format error has occurred
            * @throws IOException if an I/O error has occurred
            * @throws SecurityException if any of the jar file entries
      diff --git a/src/java.base/share/classes/java/util/zip/ZipFile.java b/src/java.base/share/classes/java/util/zip/ZipFile.java
      index a3c38acef91..1bef27986a3 100644
      --- a/src/java.base/share/classes/java/util/zip/ZipFile.java
      +++ b/src/java.base/share/classes/java/util/zip/ZipFile.java
      @@ -345,7 +345,8 @@ public class ZipFile implements ZipConstants, Closeable {
            *
            * @param entry the zip file entry
            * @return the input stream for reading the contents of the specified
      -     * zip file entry.
      +     * zip file entry or null if the zip file entry does not exist
      +     * within the zip file.
            * @throws ZipException if a ZIP format error has occurred
            * @throws IOException if an I/O error has occurred
            * @throws IllegalStateException if the zip file has been closed

      Attachments

        Issue Links

          Activity

            People

              lancea Lance Andersen
              jeff Jeff Dinkins
              Alan Bateman, Sean Mullan
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: