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

java.io.DataOutputStream constructor doesn't check null parameter

XMLWordPrintable

    • 1.2beta4
    • sparc
    • solaris_2.5
    • Not verified

      This bug was found by St.Petersburg Java SQE team (by Alexander Kuzmin).

      The java_io.DataOutputStream constructor DataOutputStream(OutputStream out)
      accepts and doesn't check null parameter. Therefore, both write(int) and
      write(byte[],int,int) methods throw non-documented NullPointerException.


      For example, the specification for java.io.DataOutputstream.write(int) says:

      The Java Language Specification Version 1.0:

      22.21.3 public void write(int b) throws IOException
      The byte for this operation (the low eight bits of the argument b) is written
       to the contained output stream. If no exception is thrown, the counter
       written is incremented by 1.

      Implements the write method of OutputStream (§22.15.1).
      _______________________Example ______________________________________
      import java.io.*;

      public class bug_tests {

        public static void main( String argv[] ) {

       DataOutputStream y1;
       byte b='1';
       
         y1 = new DataOutputStream(null);// Create DataOutputStream object
                                         // The constructor permit this.

        if ( (y1!=null) && (y1 instanceof DataOutputStream))
        {

         try {
         y1.write(b); // Try to write
         }
          catch (IOException e) // Check IOException
          {System.out.println("IOException ?!");
           return;}

          catch (Exception e) // Check other exceptions
          {System.out.println("Unexpected "+ e );
           return;
          }
        
             System.out.println("Failed - No exceptions");

         } //if ..

             System.out.println("Not object !!");

        }

      }
      _____________________Output_________________________________________

      Unexpected java.lang.NullPointerException
      ____________________________________________________________________
        

            dviswanasunw Deepa Viswanathan (Inactive)
            mgorshen Mikhail Gorshenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: