Skip to content

InputStream from Socket throws NullPointerException for Unpacker #217

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

Closed
fdinoff opened this issue Apr 27, 2015 · 2 comments
Closed

InputStream from Socket throws NullPointerException for Unpacker #217

fdinoff opened this issue Apr 27, 2015 · 2 comments

Comments

@fdinoff
Copy link
Contributor

fdinoff commented Apr 27, 2015

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?

@xerial
Copy link
Member

xerial commented Apr 27, 2015

Thanks for the report. I'll add a fix when getChannel() is null.

@xerial xerial closed this as completed in 3dbe178 Apr 27, 2015
komamitsu added a commit that referenced this issue Apr 27, 2015
Fixes #217: Handle when FileInputStream.getChannel() returns null
@xerial
Copy link
Member

xerial commented Apr 27, 2015

Try 0.7.0-p9, which will be available in a few hours.

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