This is the mail archive of the java-prs@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

libgcj/1913: reading closed streams throws NullPointerException, not IOException



>Number:         1913
>Category:       libgcj
>Synopsis:       reading closed streams throws NullPointerException, not IOException
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 08 10:16:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     paul@dawa.demon.co.uk
>Release:        gcc version 2.97 20010208 (experimental)
>Organization:
>Environment:
RedHat Linux 7.0 x86
>Description:
While trying to produce a test case for java/1912 I noticed that
reading from an InputStreamReader after a close throws a 
NullPointerException whereas in the Sun JDK it throws an IOException
with the message "Stream closed". 

import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.FileInputStream;

public class Test2 {
    public static void main(String args[]) {
	try {
	    InputStreamReader isr = new InputStreamReader(new BufferedInputStream(new FileInputStream("/dev/zero")));

	    char[] cbuf = new char[10];

	    isr.close();
	    isr.read(cbuf, 0, 9);
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}

javac Test2.java
[paul@jaffa-cake paul]$ CLASSPATH=. java Test2
java.io.IOException: Stream closed
	at java.lang.Throwable.<init>(Throwable.java:96)
	at java.lang.Exception.<init>(Exception.java:44)
	at java.io.IOException.<init>(IOException.java:49)
	at java.io.InputStreamReader.ensureOpen(InputStreamReader.java:216)
	at java.io.InputStreamReader.read(InputStreamReader.java:249)
	at Test2.main(Test2.java:14)

[paul@jaffa-cake paul]$ gcj Test2.java --main=Test2 -o test
[paul@jaffa-cake paul]$ ./test
java.lang.NullPointerException
   at 0x4017fbec: _Jv_ThrowSignal (/opt/gcc-snap/lib/libgcj.so.1)
   at 0x4017fc2d: _Jv_ThrowSignal (/opt/gcc-snap/lib/libgcj.so.1)
   at 0x401c360b: java::io::InputStreamReader::read(JArray<wchar_t>*, int, int) (/opt/gcc-snap/lib/libgcj.so.1)
   at 0x08049387: Test2::main(JArray<java::lang::String*>*) (/home/paul/Test2.java:14)
   at 0x401964db: gnu::gcj::runtime::FirstThread::run() (/opt/gcc-snap/lib/libgcj.so.1)
   at 0x401a0bcb: java::lang::Thread::run_(java::lang::Object*) (/opt/gcc-snap/lib/libgcj.so.1)
   at 0x402bc35a: _Jv_ThreadStart(java::lang::Thread*, int*, void (*)(java::lang::Thread*)) (/opt/gcc-snap/lib/libgcj.so.1)
   at 0x401a0cdf: java::lang::Thread::start() (/opt/gcc-snap/lib/libgcj.so.1)
   at 0x40180ff2: JvRunMain (/opt/gcc-snap/lib/libgcj.so.1)
   at 0x08049413: main (/tmp/ccJJ8IR6main.i:0)
   at 0x404bbe51: __libc_start_main (/lib/libc.so.6)
   at 0x080491b1: _start (??:0)
>How-To-Repeat:

>Fix:
--- libjava/java/io/InputStreamReader.java~	Wed Nov 29 10:06:03 2000
+++ libjava/java/io/InputStreamReader.java	Thu Feb  8 17:12:10 2001
@@ -71,6 +71,9 @@
   {
     synchronized (lock)
       {
+	if (in == null)
+	  throw new IOException("Stream closed");
+
 	if (wpos < wcount)
 	  return true;
 	if (work == null)
@@ -102,6 +105,9 @@
   {
     synchronized (lock)
       {
+	if (in == null)
+	  throw new IOException("Stream closed");
+
 	int wavail = wcount - wpos;
 	if (wavail > 0)
 	  {
@@ -136,6 +142,9 @@
   {
     synchronized (lock)
       {
+	if (in == null)
+	  throw new IOException("Stream closed");
+
 	int wavail = wcount - wpos;
 	if (wavail > 0)
 	  return work[wpos++];
>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]