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

ZipOutputStream.setComment(String comment) doesn't throw NullPointerException

XMLWordPrintable

    • generic
    • generic

      with b70 - java.util.zip.ZipOutputStream.setComment(String comment) doesn't throw NullPointerException when ' null ' is passed as comment.

                  Test program
      ----------------------------------------------

      import java.io.*;
      import java.util.*;
      import java.util.zip.*;

      public class setCommentTests {

        public static void main(String[] args) throws Exception {

          setCommentTests test=new setCommentTests();
          test.Test01();

          
        } // end main
        
        /**
         * Test Test01: comment = null, test should throw NullPointerException
         */
        public void Test01() {
          boolean exceptionThrown = false;
          String sComment = null;
          
          try {
           ZipOutputStream zos = new ZipOutputStream(System.out);
           zos.setComment(sComment);
          } catch (Exception e) {
           exceptionThrown = true;
              if ( e instanceof NullPointerException ) {
                System.out.println ("Expected NullPointerException thrown");
             } else {
             System.out.println ("Exception thrown, but not the expected NullPointerException");
             }
             e.printStackTrace();
          }
          
          if ( ! (exceptionThrown) ) {
            
            System.out.println ("No Exception thrown");
          }
         
        }
          
       
      }

      -------------------------------------------------------

                    TestResult with b70
      -------------------------------------------------

      No Exception thrown


                   TestResult with b69
      -----------------------------------------------------
      Expected NullPointerException thrown
      java.lang.NullPointerException
              at java.util.zip.ZipOutputStream.setComment(ZipOutputStream.java:74)
              at setCommentTests.Test01(setCommentTests.java:25)
              at setCommentTests.main(setCommentTests.java:11)

      --------------------------------------

            kkladkosunw Konstantin Kladko (Inactive)
            saksunw Sreejith Ak (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: