Skip to content

NullPointerException when using new JBBPDslBuilder #20

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
timmattison opened this issue Jul 31, 2018 · 5 comments
Closed

NullPointerException when using new JBBPDslBuilder #20

timmattison opened this issue Jul 31, 2018 · 5 comments
Assignees
Labels
Milestone

Comments

@timmattison
Copy link
Contributor

timmattison commented Jul 31, 2018

I have multiple classes that I want to convert into the DSL. Most of them work but I found a few that didn't and failed with NullPointerExceptions.

The simplest example I could come up with was:

import com.igormaznitsa.jbbp.mapper.Bin;
import com.igormaznitsa.jbbp.mapper.BinType;

public class BreakJBBPDslBuilder {
    @Bin(outOrder = 1, comment = "Reserved", type = BinType.BIT_ARRAY, extra = "4")
    public byte[] reserved;
}

If I then do this:

JBBPDslBuilder.Begin().AnnotatedClass(BreakJBBPDslBuilder.class).End();

I'll get a NullPointerException in the JBBPDslBuilder class on line 1936.

return field.bin.outBitNumber() == JBBPBitNumber.BITS_8 ? this.bin.outBitNumber() : field.bin.outBitNumber();

In this case field.bin.outBitNumber is equal to BITS_8 so it then tries to execute the this.bin.outBitNumber() method. this.bit is the field that is NULL. I went through the test suite and it looks like the this.bin field is always NULL in the tests. Is it really needed? I haven't fully understood all of the code but maybe this should've been a NULL check on field.bin?

@raydac raydac self-assigned this Jul 31, 2018
@raydac raydac added the bug label Jul 31, 2018
@raydac raydac added this to the 1.4.1 milestone Jul 31, 2018
@raydac
Copy link
Owner

raydac commented Jul 31, 2018

looks like a bug, you are parsing BIT_ARRAY type but have not provided outBitNumber attribute in the Bin annotation of the field

raydac added a commit that referenced this issue Jul 31, 2018
@raydac
Copy link
Owner

raydac commented Jul 31, 2018

I have fixed the issue, without defined outBitNumber by default it will be using default value and 8 bits per item will be read

@timmattison
Copy link
Contributor Author

👍

@timmattison
Copy link
Contributor Author

Will this be released as 1.4.1? I'd like to use it via Maven soon.

@raydac
Copy link
Owner

raydac commented Aug 1, 2018

yes, the fix will be published in 1.4.1

@raydac raydac closed this as completed Aug 1, 2018
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