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.
======================================================================
- relates to
-
JDK-4015701 java.io.ByteArrayOutputStream can throw NegativeArraySizeException
-
- Closed
-
-
JDK-4127654 Constructors for BufferedOutputStream, etc. can throw NegativeArraySizeException
-
- Closed
-