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

ZipInputStream(InputStream is) does not throw NullPointerException

XMLWordPrintable

    • jar
    • 1.2.2
    • sparc
    • solaris_2.5



      Name: sdC67446 Date: 09/18/98


      There is inconsistency in the behaviour ZipInputStream and ZipOutputStream
      constructors. The constructor java.util.zip.ZipInputStream(InputStream is)
      doesn't throw NullPointerException for 'is' == null. The same situation
      causes the ZipOutputStream(null) to throw NullPointerException.

      The doc says:
      --------------------------------------------------
      public ZipInputStream(InputStream in)

            Creates a new ZIP input stream.
            Parameters:
                  in - the actual input stream

      public ZipOutputStream(OutputStream out)

            Creates a new ZIP output stream.
            Parameters:
                  out - the actual output stream

      Please note that in both cases the doc is silent about
      passing null to the constructor.


      The test demonstrating the bug:
      -----------------Test.java------------------------
      import java.util.zip.*;

      public class Test {
        public static void main(String[] args) {
            try {
      ZipOutputStream zos = new ZipOutputStream(null);
      System.out.println("no exception");
            } catch (NullPointerException e) {
      System.out.println(e);
            }
            try {
      ZipInputStream zis = new ZipInputStream(null);
      System.out.println("no exception");
            } catch (NullPointerException e) {
      System.out.println(e);
            }
        }
      }
      ---------Output from the test---------------------
      java.lang.NullPointerException
      no exception
      --------------------------------------------------
      ======================================================================

            zlisunw Zhenghua Li (Inactive)
            sdmitriesunw Sergei Dmitriev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: