Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8079860

(bf) ByteBuffer getFloat throw BufferOverflowException while BufferUnderflowException is expected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • tbd
    • 9
    • core-libs

      After JDK-8026049, ByteBuffer.getFloat() throw BufferOverflowException while BufferUnderflowException is expected.

      Test to reproduce this issue:

      import java.nio.BufferOverflowException;
      import java.nio.BufferUnderflowException;
      import java.nio.ByteBuffer;

      public class Test {

          public static void main(String[] args) {
              int length = 4;
              float value = Float.MIN_VALUE;
              ByteBuffer buffer = ByteBuffer.allocate(length);
              buffer.putFloat(value);
              buffer.position(0);
              if (value != buffer.getFloat()) {
                  System.out.println("Test Fail: Returned value not equal to what was entered.");
              } else {
                  try {
                      value = buffer.getFloat();
                  } catch (BufferUnderflowException e) {
                      System.out.println("Test Pass: Expected Exception " + e.toString() + " thrown.");
                  } catch (BufferOverflowException e) {
                      System.out.println("Test Fail: Unexpected Exception " + e.toString() + " thrown.");
                      e.printStackTrace();
                  }
              }
          }

      }

      Expected result:
          Test Pass: Expected Exception java.nio.BufferUnderflowException thrown.

      Real result (with build after JDK-8026049)
          Test Fail: Unexpected Exception java.nio.BufferOverflowException thrown.
          java.nio.BufferOverflowException
              at java.nio.Buffer.nextPutIndex(Buffer.java:527)
              at java.nio.HeapByteBuffer.getFloat(HeapByteBuffer.java:480)
              at Test.main(Test.java:18)

            aph Andrew Haley
            amlu Amy Lu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: