Charset.encode and Charset.decode only work for a single call. The reason is that the encoder/decoder is cached and after the first call it will be in the flushed state. The second call will thus throw an InvalidStateException. Removing the cache or resetting the cached object should solve this.
This bug is fixed in GNU classpath and I will merge the needed fixes soon.
Fixed on the mainline by: 2005-04-27 Sven de Marothy <sven@physto.se> * java/nio/charset/Charset.java: Cached encoders shouldn't be static. 2005-04-27 Sven de Marothy <sven@physto.se> * java/nio/charset/Charset.java: Reset cached de/encoders. Hmm, I think these patches should be backported to 4.0.1.
Added to Tom Tromey's queue for 4.0 branch.
Note that the patch from the trunk can't be applied to the 4.0 branch, as it would break compatibility for the C++ ABI. My current leaning is to simply disable the caching in 4.0.1.
Subject: Bug 21140 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: tromey@gcc.gnu.org 2005-05-17 01:46:06 Modified files: libjava : ChangeLog libjava/java/nio/charset: Charset.java Log message: PR libgcj/21140: * java/nio/charset/Charset.java (encode, decode): Don't cache. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.3391.2.69&r2=1.3391.2.70 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/nio/charset/Charset.java.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.9&r2=1.9.2.1
Fix checked in.