-
Bug
-
Resolution: Fixed
-
P4
-
1.0.2
-
1.2beta4
-
sparc
-
solaris_2.5
-
Not verified
Name: saf@russia Date: 09/09/96
This bug was found by St.Petersburg Java SQE team (by Stanislav Avzan).
The java.io.PipedOutputStream.write(b,off,len) method does not work with null
value of b according to the Java language specification.
The Java Language specification
(Version 1.0 - August 1, 1996)
says the following (please see item 22.15.3):
"22.15.3 public void write(byte[] b, int off, int
len)
throws IOException, NullPointerException,
IndexOutOfBoundsException
The general contract for write(b, off, len) is that some of the bytes
in the array b are written to the output stream as if one at a time, in order;
element b[off] is the first byte written and b[off+len-1] is the last byte
written by this operation.
If b is null, a NullPointerException is thrown.
<....>"
So this method should throw NullPointerException
if b is null.
But in fact when len equals to 0 it does not.
Here is the minimized test demonstrating the bug:
----- test13.java ---------------------------------------
import java.io.*;
public class test13 {
public static void main( String[] argv ) {
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream();
try {
is.connect(os);
} catch(Throwable e) {
System.out.println("Test failed: unexpected <"+e+"> thrown");
}
try {
os.write(null,0,0);
System.out.println("Test failed: NullPointerException expected");
} catch(NullPointerException e) {
System.out.println("Test passed: NullPointerException thrown");
} catch(Throwable e) {
System.out.println("Test failed: unexpected <"+e+"> thrown");
}
}
}
----- The output of the test: -------------------------
$JAVA test13
Test failed: NullPointerException expected
-------------------------------------------------------
Workaround:
None
======================================================================
Name: saC57035 Date: 11/27/96
This bug was found by St.Petersburg Java SQE team (by Stanislav Avzan).
The java.io.OutputStream.write(b,off,len) and java.io.PipedOutputStream.write(b,off,len)
methods do not work with null value of b according to the Java language specification.
The Java Language specification
(Version 1.0 - August 1, 1996)
says the following (please see item 22.15.3):
"22.15.3 public void write(byte[] b, int off, int
len)
throws IOException, NullPointerException,
IndexOutOfBoundsException
The general contract for write(b, off, len) is that some of the bytes
in the array b are written to the output stream as if one at a time, in order;
element b[off] is the first byte written and b[off+len-1] is the last byte
written by this operation.
If b is null, a NullPointerException is thrown.
<....>"
So this method should throw NullPointerException
if b is null.
But in fact when len equals to 0 it does not.
Here is the minimized test demonstrating the bug for PipedOutputStream:
----- test13.java ---------------------------------------
import java.io.*;
public class test13 {
public static void main( String[] argv ) {
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream();
try {
is.connect(os);
} catch(Throwable e) {
System.out.println("Test failed: unexpected <"+e+"> thrown");
}
try {
os.write(null,0,0);
System.out.println("Test failed: NullPointerException expected");
} catch(NullPointerException e) {
System.out.println("Test passed: NullPointerException thrown");
} catch(Throwable e) {
System.out.println("Test failed: unexpected <"+e+"> thrown");
}
}
}
----- The output of the test: -------------------------
$JAVA test13
Test failed: NullPointerException expected
-------------------------------------------------------
======================================================================
- relates to
-
JDK-4177435 (test) java/io/OutputStream/WriteParams failing (WinNT, JDK1.2FCS-L)
-
- Closed
-