Patch: FYI: PR 8738

Tom Tromey tromey@redhat.com
Sun Dec 1 13:52:00 GMT 2002


I'm checking this in.

This is an updated version of the patch in PR 8738.

This patch is required to let some Java code compile against libgcj.
It's a bit ugly since our old behavior is more in keeping with Sun's
documentation, and also with the Writer contract.  Nevertheless, some
programs rely on some of the CharArrayWriter methods not throwing
IOException, so the better behavior has to go.

Tom

Index: libjava/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	Bug compatibility, for PR libgcj/8738:
	* java/io/CharArrayWriter.java (close): Do nothing.
	(flush): Likewise.
	(reset): Don't touch `closed'.
	(write(int)): Don't throw IOException.
	(write(char[],int,int)): Likewise.
	(write(String,int,int)): Likewise.
	(closed): Removed.

Index: libjava/java/io/CharArrayWriter.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/CharArrayWriter.java,v
retrieving revision 1.6
diff -u -r1.6 CharArrayWriter.java
--- libjava/java/io/CharArrayWriter.java 22 Jan 2002 22:40:13 -0000 1.6
+++ libjava/java/io/CharArrayWriter.java 1 Dec 2002 21:51:16 -0000
@@ -1,5 +1,5 @@
 /* CharArrayWriter.java -- Write chars to a buffer
-   Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -98,19 +98,13 @@
    */
   public void close ()
   {
-    closed = true;
   }
 
   /**
    * This method flushes all buffered chars to the stream.
    */
-  public void flush () throws IOException
+  public void flush ()
   {
-    synchronized (lock)
-      {
-	if (closed)
-	  throw new IOException ("Stream closed");
-      }
   }
 
   /**
@@ -123,9 +117,6 @@
     synchronized (lock)
       {
 	count = 0;
-	// Allow this to reopen the stream.
-	// FIXME - what does the JDK do?
-	closed = false;
       }
   }
 
@@ -187,13 +178,10 @@
    *
    * @param oneChar The char to be read passed as an int
    */
-  public void write (int oneChar) throws IOException
+  public void write (int oneChar)
   {
     synchronized (lock)
       {
-	if (closed)
-	  throw new IOException ("Stream closed");
-
 	resize (1);
 	buf[count++] = (char) oneChar;
       }
@@ -207,13 +195,10 @@
    * @param offset The index into the buffer to start writing data from
    * @param len The number of chars to write
    */
-  public void write (char[] buffer, int offset, int len) throws IOException
+  public void write (char[] buffer, int offset, int len)
   {
     synchronized (lock)
       {
-	if (closed)
-	  throw new IOException ("Stream closed");
-
 	if (len >= 0)
 	  resize (len);
 	System.arraycopy(buffer, offset, buf, count, len);
@@ -230,13 +215,10 @@
    * @param offset The index into the string to start writing data from
    * @param len The number of chars to write
    */
-  public void write (String str, int offset, int len) throws IOException
+  public void write (String str, int offset, int len)
   {
     synchronized (lock)
       {
-	if (closed)
-	  throw new IOException ("Stream closed");
-
 	if (len >= 0)
 	  resize (len);
 	str.getChars(offset, offset + len, buf, count);
@@ -289,9 +271,4 @@
    * The number of chars that have been written to the buffer
    */
   protected int count;
-
-  /**
-   * True if the stream has been closed.
-   */
-  private boolean closed;
 }



More information about the Java-patches mailing list