[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

java.nio.charset.CharsetEncoder.encode(java.nio.CharBuffer) doesn't conf

From: Maxence Dalmais
Subject: java.nio.charset.CharsetEncoder.encode(java.nio.CharBuffer) doesn't conform to the spec
Date: Wed, 28 Apr 2010 08:38:36 +0200

Hello ,

I got a different behavior between java-6-openJDK and CLASSPATH 0.98 with the encode(java.nio.CharBuffer) method of java.nio.charset.CharsetEncoder class.

As we can see in the source, the authors of the CharsetEncoder wasn't sure about the implementation :

// XXX: Sun's Javadoc seems to contradict itself saying an
// IllegalStateException is thrown "if a decoding operation is already
// in progress" and also that "it resets this Encoder".
 // Should we check to see that the state is reset, or should we
 // call reset()?

In fact, in the spec,  we can see the this method "implements an entire encoding operation; that is, it resets this encoder, then it encodes the characters in the given character buffer, and finally it flushes this encoder. This method should therefore not be invoked if an encoding operation is already in progress."

In the current implementation of the class, we have an internal state, which can be STATE_RESET,STATE_CODING , STATE_END or STATE_FLUSHED.

I think that we should call the reset() method if the state is STATE_FLUSHED and/or STATE_END (I am not sur about this) and throw exception if the state is STATE_CODING.

What do you think about it ?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]