Hey all
The attached CharsetEncoderTest.java fails on Windows with an
IllegalStateException. It works on Linux. I don't know why, but I assume
because it doesn't need a CharsetEncoder. There's for sure a better
example that shows the bug which would fail on Windows and Linux, but I
was already satisfied with this one.
The problem is that this sequence will be called:
1. encode (CharBuffer in, ByteBuffer out,
boolean endOfInput = true)
-> state will be "STATE_END"
2. flush (ByteBuffer out)
-> state will be "STATE_FLUSHED" what is basically the same as "STATE_END"
3. encode (CharBuffer in, ByteBuffer out,
boolean endOfInput = true)
Step three now throws an IllegalStateException exception since it
doesn't recognize "STATE_FLUSHED" as valid. If there weren't the call to
flush, the second call to encode would work.
So my proposed patch adds "STATE_FLUSHED" as valid state.
Changelog suggestion:
classpath/java/nio/charset/CharsetEncoder.java (encode):
Add "STATE_FLUSHED" as valid state.
Can someone please approve and, if it's valid, commit that change?
thanks
Marco
public class CharsetEncoderTest
{
public static void main(String[] args)
{
try
{
"abc".getBytes("unicode");
} catch(java.io.UnsupportedEncodingException ex)
{
System.err.println("unsupported encoding exception");
}
}
}
Index: classpath/java/nio/charset/CharsetEncoder.java
===================================================================
--- classpath/java/nio/charset/CharsetEncoder.java (revision 122233)
+++ classpath/java/nio/charset/CharsetEncoder.java (working copy)
@@ -200,6 +200,7 @@
// XXX: We will not check the previous return value, just
// that the previous call passed true for endOfInput
if (state != STATE_RESET && state != STATE_CODING
+ && state != STATE_FLUSHED
&& !(endOfInput && state == STATE_END))
throw new IllegalStateException ();
state = newState;