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

java.io.PushbackReader with negative or zero length pushback buffer

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs
    • x86
    • windows_nt



      Name: bb33257 Date: 05/12/98


      Create a PushbackReader with a negative pushback buffersize and
      one with a zero length pushback buffersize. Here is the code:
      ------------------------------
      import java.io.*;
      import java.lang.reflect.*;
      import java.lang.*;

      public class foo {

          /* Standalone interface */
          public static void main( String[] argv ) throws IOException {
              StringReader rdr = new StringReader("now is the time for all good");
              char[] buffer = new char[28];
              int len;
              PushbackReader prdr1 = new PushbackReader(rdr, 0);
              len = prdr1.read(buffer);
              System.out.println(buffer);
              PushbackReader prdr2 = new PushbackReader(rdr, -10);
              System.exit(0);
          }

      }
      ------------------------------
      Output from this program is

      now is the time for all good
      java.lang.NegativeArraySizeException:
              at java.io.PushbackReader.<init>(PushbackReader.java:45)
              at foo.main(foo.java:22)
      ------------------------------

      The zero length pushback buffer is accepted and you can read using
      it. This should raise an IllegalArgumentException, as
      should the negative value in the PushbackReader's constructor.
      ======================================================================

            zlisunw Zhenghua Li (Inactive)
            bcbeck Brian Beck (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: