Skip to content

InputStream from Socket throws NullPointerException for Unpacker #217

Description

@fdinoff

Version: 0.7.0-p8

I'm trying to create an unpacker from a socket's input stream. It currently throws a NullPointerException

MessagePack msgPack = new MessagePack();
Socket socket = new Socket("127.0.0.1", 6666);
msgPack.newUnpacker(socket.getInputStream());

Stack Trace

Exception in thread "main" java.lang.NullPointerException: input channel is null
    at org.msgpack.core.Preconditions.checkNotNull(Preconditions.java:203)
    at org.msgpack.core.buffer.ChannelBufferInput.<init>(ChannelBufferInput.java:23)
    at org.msgpack.core.buffer.ChannelBufferInput.<init>(ChannelBufferInput.java:19)
    at org.msgpack.core.buffer.InputStreamBufferInput.newBufferInput(InputStreamBufferInput.java:21)
    at org.msgpack.core.MessagePack.newUnpacker(MessagePack.java:360)

This happens inside InputStreamBufferInput.newBufferInput since the InputStream from the socket is a FileInputStream however It doesn't have a channel

public static MessageBufferInput newBufferInput(InputStream in) {
    checkNotNull(in, "InputStream is null");
    if (in instanceof FileInputStream) {
        return new ChannelBufferInput(((FileInputStream) in).getChannel());
    }
    return new InputStreamBufferInput(in);

}

How should I create an unpacker from a socket?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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