raydac/java-binary-block-parser

NullPointerException when using new JBBPDslBuilder

timmattison opened this issue · 5 comments

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?

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

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

👍

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

yes, the fix will be published in 1.4.1