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

NPE in toString method of generated decoder #708

Closed
fzn7 opened this issue Aug 16, 2019 · 0 comments
Closed

NPE in toString method of generated decoder #708

fzn7 opened this issue Aug 16, 2019 · 0 comments
Assignees
Labels

Comments

@fzn7
Copy link

fzn7 commented Aug 16, 2019

It seems java codegen tool not fully aware of optional fields. We are getting NPE during decode our new traceContext2 field. This field is available since version 3 of our schema and marked as optional.

<field xmlns="" name="traceContext2" id="4" type="TraceContext" description="Distributed Trace Context" presence="optional" sinceVersion="3"/>

If we will try to send message with version 2 and call toString we will obtain an NPE

Reported exception:
java.lang.NullPointerException
        at com.mlp.ctp.generic.MessageAckDecoder.appendTo(MessageAckDecoder.java:352)
        at com.mlp.ctp.generic.MessageAckDecoder.toString(MessageAckDecoder.java:308)

Generated code:

toString:

builder.append('|');
builder.append("traceContext2=");
this.traceContext2().appendTo(builder);

traceContext2() method:

public TraceContextDecoder traceContext2() {
    if (this.parentMessage.actingVersion < 3) {
        return null;
    } else {
        this.traceContext2.wrap(this.buffer, this.offset + 16);
        return this.traceContext2;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants