MINA
  1. MINA
  2. DIRMINA-836

AbstractIoBuffer.putUnsignedXXX(int index, xxx value) methods disregard index

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.3
    • Fix Version/s: 2.0.4
    • Component/s: Core
    • Labels:
      None

      Description

      Relates to DIRMINA-823, where these methods were first introduced.

      All the "indexed" putUnsignedXXX() methods disregard the index when writing to the underlying buffer.
      For example:

      public final IoBuffer putUnsignedInt(int index, byte value)

      { autoExpand(index, 4); buf().putInt( (int)((short)value&0x00ff) ); // --------------- ^^^^ --- should pass 'index' in as the first parameter return this; }

      The test cases in Mina core, attached to revision 1090588, do not catch this because although they use indexed puts, they use unindexed gets (had they used symmetrical indexed gets, they would have failed). A code snippet that demonstrates the problem is below:

      final IoBuffer buffer = IoBuffer.allocate(128);
      buffer.putUnsignedInt(10, 0x87654321L);
      buffer.putUnsignedInt(20, 0xFFFFFFFFL);
      System.out.printf("buffer.getUnsignedInt(0) = 0x%08X\n", buffer.getUnsignedInt(0));
      System.out.printf("buffer.getUnsignedInt(4) = 0x%08X\n", buffer.getUnsignedInt(4));
      System.out.printf("buffer.getUnsignedInt(10) = 0x%08X\n", buffer.getUnsignedInt(10));
      System.out.printf("buffer.getUnsignedInt(20) = 0x%08X\n", buffer.getUnsignedInt(20));

      A trivial fix is required, which is to pass 'index' parameter to buf().putInt() or buf().putShort() method call.

        Activity

        Hide
        Sergei Ivanov added a comment -

        Also, a minor thing:
        putUnsignedInt(long) should append 'L' to the bit mask constant:
        buf().putInt( (int)(value&0x00000000ffffffffL) );

        Show
        Sergei Ivanov added a comment - Also, a minor thing: putUnsignedInt(long) should append 'L' to the bit mask constant: buf().putInt( (int)(value&0x00000000ffffffffL) );
        Hide
        Emmanuel Lecharny added a comment -

        Rahhh... My bad. Will fix that.

        Show
        Emmanuel Lecharny added a comment - Rahhh... My bad. Will fix that.

          People

          • Assignee:
            Julien Vermillard
            Reporter:
            Sergei Ivanov
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development