JDK-8079860 : (bf) ByteBuffer getFloat throw BufferOverflowException while BufferUnderflowException is expected
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 9
  • Priority: P2
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2015-05-09
  • Updated: 2015-12-16
  • Resolved: 2015-12-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_minorResolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
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)