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

java.io.ByteArrayOutputStream can throw NegativeArraySizeException

    XMLWordPrintable

Details

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

    Description

      The documentation for java.io.ByteArrayOutputStream constructor
      does not mention NegativeArraySizeException. This exception
      is thrown when negative parameter is passed to the constructor.

      _______ Specification for ByteArrayOutputStream(int) _______
      22.18.4 public ByteArrayOutputStream(int size)

      This constructor initializes a newly created ByteArrayOutputStream so that
      its internal buffer array has length size. This matters only for reasons
      of efficiency; the buffer array is replaced by a larger one whenever necessary
      to accommodate additional bytes written to the stream.

      _______________________ Example ______________________________________
      import java.io.*;

      public class bug_tests {

       public static void main( String argv[] ) {
         
        try {
       ByteArrayOutputStream y1 = new ByteArrayOutputStream(-1); // Create new object
        } catch (NegativeArraySizeException e) // Catch the exception
          { System.out.println(" It is expected but non-documented exception:"+e);
          }

          catch (Exception e)
          {
           System.out.println(" Unexpected exception:"+e);
          }
        }
      }
      _____________________Output__________________________________________
      It is expected but non-documented exception:java.lang.NegativeArraySizeException
      ____________________________________________________________________
        

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: