This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: fix no-progress InputStreamReader bug
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 06 Jul 2005 14:03:06 -0600
- Subject: Patch: FYI: fix no-progress InputStreamReader bug
- Reply-to: tromey at redhat dot com
I'm checking this in on the trunk. Most likely I will put it in 4.0
once the branch reopens.
We noticed that ecj was hanging on some sources when given '-encoding
utf8'. There are two bugs here.
First, 'utf8' was getting the iconv converter and not our built-in
UTF-8 converter. I added a new alias for this.
Second, we had a regression in InputStreamReader. There is a
situation in the current code where InputStreamReader will make no
progress and thus will hang. The fix is to notice this and play a
mark/reset game so we can refill the buffer. This is a hack, but
hopefully all this code will be going away once the nio stuff is done.
I added a new mauve test case for this failure.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* java/io/InputStreamReader.java (refill): Handle no-progress
case correctly.
* gnu/gcj/convert/IOConverter.java: Add 'utf8' alias.
Index: java/io/InputStreamReader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/InputStreamReader.java,v
retrieving revision 1.20
diff -u -r1.20 InputStreamReader.java
--- java/io/InputStreamReader.java 30 Jun 2005 03:19:49 -0000 1.20
+++ java/io/InputStreamReader.java 6 Jul 2005 20:03:20 -0000
@@ -289,9 +289,23 @@
return -1;
converter.setInput(in.buf, in.pos, in.count);
int count = converter.read(buf, offset, length);
- in.skip(converter.inpos - in.pos);
- if (count > 0)
- return count;
+
+ // We might have bytes but not have made any progress. In
+ // this case we try to refill. If refilling fails, we assume
+ // we have a malformed character at the end of the stream.
+ if (count == 0 && converter.inpos == in.pos)
+ {
+ in.mark(in.count);
+ if (! in.refill ())
+ throw new CharConversionException ();
+ in.reset();
+ }
+ else
+ {
+ in.skip(converter.inpos - in.pos);
+ if (count > 0)
+ return count;
+ }
}
}
}
Index: gnu/gcj/convert/IOConverter.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/convert/IOConverter.java,v
retrieving revision 1.7
diff -u -r1.7 IOConverter.java
--- gnu/gcj/convert/IOConverter.java 20 Mar 2004 00:24:49 -0000 1.7
+++ gnu/gcj/convert/IOConverter.java 6 Jul 2005 20:03:20 -0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2001 Free Software Foundation
+/* Copyright (C) 2000, 2001, 2005 Free Software Foundation
This file is part of libgcj.
@@ -28,6 +28,8 @@
// canonical name.
hash.put ("iso-latin-1", "8859_1");
hash.put ("iso8859_1", "8859_1");
+ // At least one build script out there uses 'utf8'.
+ hash.put ("utf8", "UTF8");
// On Solaris the default encoding, as returned by nl_langinfo(),
// is `646' (aka ASCII), but the Solaris iconv_open() doesn't
// understand that. We work around the problem by adding an