Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-622

Initialise return ByteBuffer from PoolByteBufferAllokator with 0

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 1.1.7
    • 1.1.8
    • Core
    • None

    Description

      A ByteBuffer returned by calling ByteBuffer.allocate() on a PooledByteBufferAllocator is not guarenteed to be initialised to 0 as it would be if a SimpleByteBufferAllocator was used.

      The java equivalent java.nio.ByteBuffers are always initialised with 0 hence the MINA variant should also follow this convention independent if PooledByteBufferAllocator was used or not.

      import org.apache.mina.common.ByteBuffer;

      public class PooledByteBufferTest {

      public static void main(String[] args)

      { ByteBuffer.setAllocator(new PooledByteBufferAllocator()); ByteBuffer buffer1 = ByteBuffer.allocate(100); System.out.println("buffer1[0]=" + buffer1.getInt(0)); // prints 0 buffer1.putInt(42); System.out.println("buffer1[0]=" + buffer1.getInt(0)); // prints 42 buffer1.release(); ByteBuffer buffer2 = ByteBuffer.allocate(100); System.out.println("buffer1[0]=" + buffer2.getInt(0)); // prints 42 instead of 0 }

      }

      Attachments

        Issue Links

          Activity

            People

              ted_kods Edouard De Oliveira
              steff Stefan Gmeiner
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: