Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
t-horikawa opened this issue Nov 18, 2021 · 1 comment

Comments

@t-horikawa
Copy link

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.
@xerial
Copy link
Member

xerial commented Jun 28, 2022

I think this is a JDK17-specific issue, which will be fixed in #660.

Adding two JVM options would be necessary:

--add-opens=java.base/java.nio=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants