mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Lecharny (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (DIRMINA-829) AbstractIoBuffer.getSlice(int index, int length) has incorrect behavior
Date Tue, 10 Jul 2012 14:50:36 GMT

     [ https://issues.apache.org/jira/browse/DIRMINA-829?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Emmanuel Lecharny resolved DIRMINA-829.
---------------------------------------

    Resolution: Fixed

Fixed with http://svn.apache.org/viewvc?rev=1359706&view=rev
                
> AbstractIoBuffer.getSlice(int index, int length) has incorrect behavior
> -----------------------------------------------------------------------
>
>                 Key: DIRMINA-829
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-829
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.0.2
>            Reporter: Anton Sitnikov
>            Assignee: Emmanuel Lecharny
>            Priority: Minor
>             Fix For: 2.0.5
>
>
> All indexed access function of IoBuffer (getXXX(int index, ...)) supposed to keep IoBuffer
state intact. getSlice(int index, int length) method in AbstractIoBuffer class behave differenlty.
After its execution buffer posistion is moved to value of index parameter:
> {code}
>     public final IoBuffer getSlice(int index, int length) {
>         if (length < 0) {
>             throw new IllegalArgumentException("length: " + length);
>         }
>         
>         int limit = limit();
>         
>         if (index > limit) {
>             throw new IllegalArgumentException("index: " + index);
>         }
>         
>         int endIndex = index + length;
>         if (capacity() < endIndex) {
>             throw new IndexOutOfBoundsException("index + length (" + endIndex
>                     + ") is greater " + "than capacity (" + capacity() + ").");
>         }
>         clear();
>         position(index);
>         limit(endIndex);
>         IoBuffer slice = slice();
>         position(index);
>         limit(limit);
>         return slice;
>     }
> {code}
> As you can see, this method checks also resulting slice upper limit against original
buffer capcity (not against limit), which I suppose is wrong too.
> I think this method should be changed like this:
> {code}
>     public final IoBuffer getSlice(int index, int length) {
>         if (length < 0) {
>             throw new IllegalArgumentException("length: " + length);
>         }
>         
>         int pos = position();
>         int limit = limit();
>         
>         if (index > limit) {
>             throw new IllegalArgumentException("index: " + index);
>         }
>         
>         int endIndex = index + length;
>         if (endIndex > limit) {
>             throw new IndexOutOfBoundsException("index + length (" + endIndex
>                     + ") is greater " + "than limit (" + limit + ").");
>         }
>         clear();
>         position(index);
>         limit(endIndex);
>         IoBuffer slice = slice();
>         position(pos);
>         limit(limit);
>         return slice;
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message