JDK-6227608 : (cs) Charset-X-Coder.flush cannot be reinvoked in case of overflow
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 5.0,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-02-10
  • Updated: 2017-05-19
  • Resolved: 2005-09-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b53Fixed
Related Reports
Duplicate :  
Relates :  
Description
The spec for CharsetEncoder.flush states

If this method completes successfully then it returns CoderResult.UNDERFLOW. If there is insufficient room in the output buffer then it returns CoderResult.OVERFLOW. If this happens then this method must be invoked again, with an output buffer that has more room, in order to complete the current encoding operation.

However, the implementation unconditionally throws an IllegalStateException
if flush is invoked twice, even if it returned UNDERFLOW the first time.
This happens with any encoder or decoder with a non-trivial flush method.

Exception in thread "main" java.lang.IllegalStateException: Current state = FLUSHED, new state = FLUSHED

###@###.### 2005-2-10 02:34:26 GMT

Comments
SUGGESTED FIX --- /tmp/geta3881 2005-02-09 18:33:29.723541400 -0800 +++ Charset-X-Coder.java 2005-02-09 12:57:19.228217000 -0800 @@ -622,16 +622,18 @@ * #$code$($Itype$Buffer,$Otype$Buffer,boolean) $code$} method * with a value of <tt>true</tt> for the <tt>endOfInput</tt> * parameter */ public final CoderResult flush($Otype$Buffer out) { if (state != ST_END) throwIllegalStateException(state, ST_FLUSHED); - state = ST_FLUSHED; - return implFlush(out); + CoderResult cr = implFlush(out); + if (cr.isUnderflow()) + state = ST_FLUSHED; + return cr; } /** * Flushes this $coder$. * * <p> The default implementation of this method does nothing, and always * returns {@link CoderResult#UNDERFLOW}. This method should be overridden ###@###.### 2005-2-10 02:34:27 GMT
10-02-2005

EVALUATION The implementation of flush does an unconditional state transition to FLUSHED. However, if there is an overflow, the flush operation hasn't really completed, and the state should remain unchanged. ###@###.### 2005-2-10 02:34:27 GMT
10-02-2005