JDK-8080904 : ByteBuffer.get(byte[]...) fails to get the buffer content "intermittently"
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Priority: P1
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2015-05-21
  • Updated: 2015-12-22
  • Resolved: 2015-12-22
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.
Related Reports
Duplicate :  
Relates :  
During  the investigation of JDK-8080803, it is noticed that the possible trigger might be the ByteBuffer.get(byte[]) fails to get the corresponding bytes from the bytebuffer, the returned byte[] does not contain the any content ("zero" in our test case).

I'm not sure if they are related, the attached test case always fails (ByteBuffer.get(byte[]) fails to get the content) after 10k+ iteration on my local 32-bit linux build (very old  machine/os). Recently I have to update the hotspot source code (2 64-bit constants) to let the hotspot build to finish, as the compiler complains the constant is out of the range of a "long" ...



import java.nio.*;
import java.nio.charset.*;

public class Foo {

    public static void main(String[] args) throws Throwable {

        int N = Integer.parseInt(args[0]);
        CharsetEncoder enc = Charset.forName("EUC_KR").newEncoder();
        byte[] bytes = new byte[8];
        for (int i = 0; i < N; i++) {
            if (encode(enc, '\u4e00', bytes) == 2) {
                if (bytes[0] == 0 && bytes[1] == 0) {
                    throw new RuntimeException("FAILED: b[0]=" + bytes[0] + ",b[1]=" + bytes[1]);
                } else {
                    System.out.printf("[%d] 0x%x%x%n", i, bytes[0] & 0xff, bytes[1]&0xff);

    private static int encode(CharsetEncoder enc, char unicode, byte ebyte[]) {
        int index = 0;
        char        convChar[] = {unicode};
        byte        convByte[] = new byte[4];
        int         converted;

            CharBuffer cc = CharBuffer.wrap(convChar);
            ByteBuffer bb = ByteBuffer.allocate(4);
            enc.encode(cc, bb, true);
            converted = bb.remaining();
        } catch(Exception e) {
            return -1;
        if (converted == 2) {
            ebyte[index++] = (byte)(convByte[0] & 0x7f);
            ebyte[index++] = (byte)(convByte[1] & 0x7f);
        return converted;
Reproduced with jdk9 b66 through jdk9 b82, gone in b83 and later. Test passes with -XX:-Inline or -XX:-DoEscapeAnalysis, so it looks like JDK-8134031 is the likely cause.

ILW=incorrect return values;c2 code;none=HMH=>P1

Aside: CONST64/UCONST64 macros should be used rather than direct LL/ULL suffix