On 10/16/07, Yigal Rachman <[EMAIL PROTECTED]> wrote: > Hi, Folks: > > When ByteBuffer.getString() breaks midway because of a > CharacterCodingException, it fails to restore the position and limit; > thus getString() is destructive when this happens. One can, of course, > work around this, but it should not be necessary.
Could you please specify some example code that reproduces the problem? We already have a test case for the same case, and it seems to work fine: public void testGetStringWithFailure() throws Exception { String test = "\u30b3\u30e1\u30f3\u30c8\u7de8\u96c6"; ByteBuffer buffer = ByteBuffer.wrap(test.getBytes("Shift_JIS")); // Make sure the limit doesn't change when an exception arose. int oldLimit = buffer.limit(); int oldPos = buffer.position(); try { buffer.getString(3, Charset.forName("ASCII").newDecoder()); Assert.fail(); } catch (Exception e) { Assert.assertEquals(oldLimit, buffer.limit()); Assert.assertEquals(oldPos, buffer.position()); } try { buffer.getString(Charset.forName("ASCII").newDecoder()); Assert.fail(); } catch (Exception e) { Assert.assertEquals(oldLimit, buffer.limit()); Assert.assertEquals(oldPos, buffer.position()); } } HTH, Trustin -- what we call human nature is actually human habit -- http://gleamynode.net/ -- PGP Key ID: 0x0255ECA6