-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
1.0.2
-
sparc
-
solaris_2.5
This bug was found by St.Petersburg Java SQE team (by Stanislav Avzan).
The java_io.FilterInputStream constructor FilterInputStream(InputStream in)
accept and do not check null parameter. Every call to FilterInputStream
object which is created using null, results in throwing undocumented
NullPointerException.
Here is the excerpt from Java Language Specification Version 1.0:
"22.9.3 public int read() throws IOException
This method simply performs in.read() and returns the result.
Implements the read method of InputStream (p.22.3.1)."
But if in is null, unexpected NullPointerException is thrown
Here is the example demonstrating this bug
_______________________Test.java ______________________________________
import java.io.*;
public class Test {
public static void main( String argv[] ) {
MyFilterInputStream is = new MyFilterInputStream(null);
try {
is.read();
System.out.println("No exceptions - rather strange but alright");
} catch (IOException e) {
System.out.println("IOException is thrown - possible result");
} catch (Throwable e) {
System.out.println(e+" is thrown - this is not allowed");
}
}
}
class MyFilterInputStream extends FilterInputStream {
public MyFilterInputStream (InputStream in) { super(in); }
}
_____________________Output_________________________________________
java.lang.NullPointerException is thrown - this is not allowed
____________________________________________________________________
The java_io.FilterInputStream constructor FilterInputStream(InputStream in)
accept and do not check null parameter. Every call to FilterInputStream
object which is created using null, results in throwing undocumented
NullPointerException.
Here is the excerpt from Java Language Specification Version 1.0:
"22.9.3 public int read() throws IOException
This method simply performs in.read() and returns the result.
Implements the read method of InputStream (p.22.3.1)."
But if in is null, unexpected NullPointerException is thrown
Here is the example demonstrating this bug
_______________________Test.java ______________________________________
import java.io.*;
public class Test {
public static void main( String argv[] ) {
MyFilterInputStream is = new MyFilterInputStream(null);
try {
is.read();
System.out.println("No exceptions - rather strange but alright");
} catch (IOException e) {
System.out.println("IOException is thrown - possible result");
} catch (Throwable e) {
System.out.println(e+" is thrown - this is not allowed");
}
}
}
class MyFilterInputStream extends FilterInputStream {
public MyFilterInputStream (InputStream in) { super(in); }
}
_____________________Output_________________________________________
java.lang.NullPointerException is thrown - this is not allowed
____________________________________________________________________
- relates to
-
JDK-4016185 java.io.FilterOutputStream constructor does not check null parameter
-
- Closed
-