Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-7241

ByteBuffer to String conversion uses buffer capacity not limit

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.12.3
    • 2.11.5, 2.12.4, 2.13.0
    • camel-core
    • None
    • Novice

    Description

      Camel's conversion logic for ByteBuffer's to String's has a bug where camel uses a ByteBuffers capacity() instead of it's limit().

      If you allocate a large byte buffer and only partially fill it with data, and use camel to convert this into a string, camel tries to convert all the bytes, even the non-used ones.

      This unit test reproduces this bug.

          @Test
          public void testByteBufferToStringConversion()
          {
              String str = "123456789";
              ByteBuffer buffer = ByteBuffer.allocate( 16 );
              buffer.put( str.getBytes() );
      
              Exchange exchange = new DefaultExchange( context() );
              exchange.getIn().setBody( buffer );
              assertEquals( str, exchange.getIn().getBody( String.class ) );
          }
      

      Attachments

        Activity

          People

            njiang Willem Jiang
            aaronjwhiteside Aaron Whiteside
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified