Skip to content

Illegal reflective access by org.msgpack.core.buffer.DirectBufferAccess #605

@t-horikawa

Description

@t-horikawa

When I run my program, I get a warning message with the title. The message also said "Please consider reporting this to the maintainers of org.msgpack.core.buffer.DirectBufferAccess", so I will report it here.

A simple reproduction program (named ReproduceCase.java) is below.

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.msgpack.core.MessagePack;
import org.msgpack.core.MessagePacker;
import org.msgpack.core.MessageUnpacker;
import org.msgpack.core.buffer.ByteBufferInput;

public final class ReproduceCase {
    class ByteBufferBackedInput extends ByteBufferInput {
        ByteBufferBackedInput(ByteBuffer byteBuffer) {
            super(byteBuffer);
        }
    }

    ReproduceCase() {
    }

    ByteBufferInput encode() throws IOException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        MessagePacker packer = org.msgpack.core.MessagePack.newDefaultPacker(outputStream);

        packer.packLong((long) 123456789);
        packer.flush();

        byte[] ba = outputStream.toByteArray();
        var length = ba.length;

        var directByteBuffer = ByteBuffer.allocateDirect(length);
        directByteBuffer.put(ba, 0, length);
        directByteBuffer.rewind();

        return new ByteBufferBackedInput(directByteBuffer);
    }

    void decode(ByteBufferInput buffer) throws IOException {
        var unpacker = org.msgpack.core.MessagePack.newDefaultUnpacker(buffer);
        System.out.println(unpacker.unpackLong());
    }

    public static void main(String[] args) {
        try {
            var reproduce = new ReproduceCase();
            var buffer = reproduce.encode();
            reproduce.decode(buffer);
        } catch (IOException e) {
            System.out.println(e);
        }
    }
}

The warning message is output when the following line is executed.

        var unpacker = org.msgpack.core.MessagePack.newDefaultUnpacker(buffer);

The following is supplementary information.

  1. This happens with both msgpack-core-0.8.24 and 0.9.0.
  2. unpacker.unpackLong() works fine, as you can see when you run the program.
  3. If you used ByteBuffer.allocate(length) instead of ByteBuffer.allocateDirect(length), you will not get that warning. However, that is not a solution for me because my program needs to use direct byte buffer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions