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

Null point exception in StringEncoder of Netty 3.5.1 #28

Closed
irwinmc opened this issue Dec 10, 2012 · 7 comments
Closed

Null point exception in StringEncoder of Netty 3.5.1 #28

irwinmc opened this issue Dec 10, 2012 · 7 comments

Comments

@irwinmc
Copy link

irwinmc commented Dec 10, 2012

Netty StringEncoder:

...
@OverRide
protected Object encode(
ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
if (!(msg instanceof String)) {
return msg;
}
return copiedBuffer(ctx.getChannel().getConfig().getBufferFactory().getDefaultOrder(), (String) msg, charset);
}
...

NettyUtils:
ChannelBuffer strBuffer = (ChannelBuffer) super.encode(null, null, msg);

The ChannelHandlerContext can not be null.

My version of writeString():

public static ChannelBuffer writeString(String msg) {
    ChannelBuffer buffer = null;
    try {
        ChannelBuffer stringBuffer = ChannelBuffers.dynamicBuffer();
        stringBuffer.writeBytes(msg.getBytes(CharsetUtil.UTF_8));
        int length = stringBuffer.readableBytes();
        ChannelBuffer lengthBuffer = ChannelBuffers.buffer(2);
        lengthBuffer.writeShort(length);
        buffer = ChannelBuffers.wrappedBuffer(lengthBuffer, stringBuffer);
    } catch (Exception e) {
        LOG.error("Error occurred while trying to write string to buffer: {}", e);
    }
    return buffer;
}

OR, which version of netty does not have this problem?...

@menacher
Copy link
Owner

Jetserver is using 3.3.1.Final. This one does not seem to have the problem. I had requested Netty team long time back if they could make their encoding/decoding logic to be more re-usable, seems we are going in opposite direction!
Thanks for pointing it out, I will put in the fix you provided.

@irwinmc
Copy link
Author

irwinmc commented Dec 11, 2012

:p I'm trying to use netty 4.x. But there are so many difference between 3.x and 4.x.

@irwinmc
Copy link
Author

irwinmc commented Dec 11, 2012

BTW, may I ask another question:
I use jetserver send data to flex client by amfEncoder, no big problem using netty 3.5.1, but if I change netty to a different version (3.5.9 e.g.), some strange execption will be thrown. "unknown amf type".
Is it caused by BlazeDS or netty ?

@menacher
Copy link
Owner

Without checking its hard to say. If you check the jetserver unit test cases, you can see usage of a DecoderEmbedder and EncoderEmbedder provided by netty. Simulate a pipeline using these and use a netty version in which its not working and try it out. In the mean time I will see if my flash client works for these versions of Netty.

@menacher
Copy link
Owner

I have checked in the fix for NPE occurring in later versions of Netty for string encoder/decoder. Binaries are not updated, please take latest code and build.

@irwinmc
Copy link
Author

irwinmc commented Dec 12, 2012

Thanks!

@menacher
Copy link
Owner

Could you attach an example java object you are serializing to amf? I can run a test case and see whats messing up.

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