You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Yigal Rachman <yi...@uvic.ca> on 2007/10/15 23:50:37 UTC

ByteBuffer getString() confused after CharacterCodingException

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.

Yigal Rachman

Re: ByteBuffer getString() confused after CharacterCodingException

Posted by Trustin Lee <tr...@gmail.com>.
On 10/16/07, Yigal Rachman <yi...@uvic.ca> 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

Re: ByteBuffer getString() confused after CharacterCodingException

Posted by Trustin Lee <tr...@gmail.com>.
On 10/16/07, Yigal Rachman <yi...@uvic.ca> 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.

Thanks for reporting the bug.  You can keep tracking via the following page:

https://issues.apache.org/jira/browse/DIRMINA-460

Thanks,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6