[
https://issues.apache.org/jira/browse/DIRMINA-664?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12677199#action_12677199
]
Emmanuel Lecharny commented on DIRMINA-664:
-------------------------------------------
Hmmm, I'm a bit off rails here.
Basically, you're right : the EMPY_BUFFER won't point on an empty buffer
despite the 'static final' qualifier.
After having reviewed the current implementation this afternoon, here is what I
think :
- it will be removed in 3.0
- extensible buffer is a bad idea
- using an EMPTY_BUFFER instead of allocating a buffer is not likely to happen
often
- In any case, it's not immutable, so it should not be visible to users if we
are to use them internally
So I tend to think that, yes, it's a weakness in the class. The object should
be declared private, as it's only used internally. Let's do that atm.
> EMPTY_* IoBuffer constants can be made mutable and cause data errors
> --------------------------------------------------------------------
>
> Key: DIRMINA-664
> URL: https://issues.apache.org/jira/browse/DIRMINA-664
> Project: MINA
> Issue Type: Bug
> Components: Core
> Affects Versions: 2.0.0-M4
> Environment: All?
> Reporter: David Rosenstrauch
> Priority: Minor
>
> The EMPTY_* constants in the IoBuffer class can be made mutable (by using the
> setAutoExpand(true) method call) which can result in those constant buffers
> no longer being empty. This can obviously cause a multitude of data errors.
> See this JUnit test case for an example:
> import junit.framework.TestCase;
> import org.apache.mina.core.buffer.IoBuffer;
> public class TestIoBuffer extends TestCase {
> public void testIoBufferAllocate() {
> IoBuffer buf = IoBuffer.allocate(0).setAutoExpand(true);
> buf.putInt(1234);
> buf.flip();
> buf = IoBuffer.allocate(0);
> assertEquals(0, buf.remaining());
> }
> public void testEmptyIoBuffer() {
> IoBuffer buf = IoBuffer.EMPTY_BUFFER.setAutoExpand(true);
> buf.putInt(1234);
> buf.flip();
> buf = IoBuffer.EMPTY_BUFFER;
> assertEquals(0, buf.remaining());
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.