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

java.io.FilterInputStream constructor does not catch null parameter

XMLWordPrintable

    • sparc
    • solaris_2.5

      This bug was found by St.Petersburg Java SQE team (by Stanislav Avzan).

      The java_io.FilterInputStream constructor FilterInputStream(InputStream in)
      accept and do not check null parameter. Every call to FilterInputStream
      object which is created using null, results in throwing undocumented
      NullPointerException.

      Here is the excerpt from Java Language Specification Version 1.0:

      "22.9.3 public int read() throws IOException

      This method simply performs in.read() and returns the result.

      Implements the read method of InputStream (p.22.3.1)."

      But if in is null, unexpected NullPointerException is thrown

      Here is the example demonstrating this bug

      _______________________Test.java ______________________________________
      import java.io.*;

      public class Test {

      public static void main( String argv[] ) {

       MyFilterInputStream is = new MyFilterInputStream(null);
       try {
         is.read();
         System.out.println("No exceptions - rather strange but alright");
       } catch (IOException e) {
         System.out.println("IOException is thrown - possible result");
       } catch (Throwable e) {
         System.out.println(e+" is thrown - this is not allowed");
       }
      }

      }

      class MyFilterInputStream extends FilterInputStream {
      public MyFilterInputStream (InputStream in) { super(in); }
      }
      _____________________Output_________________________________________

      java.lang.NullPointerException is thrown - this is not allowed
      ____________________________________________________________________
        

            zlisunw Zhenghua Li (Inactive)
            mgorshen Mikhail Gorshenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: