NullPointer exception when referencing a JBBPCustomFieldTypeProcessor parsed field
alastairmccormack opened this issue · 4 comments
I've written a JBBPCustomFieldTypeProcessor to parse uint32 fields into Java longs: https://gist.github.com/use-sparingly/ac1539784af7ae7569cd50135016cf2c
It seems to work for single, read all ([_]) and defined length arrays ([1]). However, if I try to reference the value as a field length in a subsequent field I get a nullpointer exception.
Example:
final JBBPParser sasParser = JBBPParser.prepare(
">uint32 keycount;" +
"key [keycount] {" +
"byte[1] contentId; " +
"byte[1] keyData; " +
"}"
, new Uint32()
);
final String inputSHex = "00000001fc05";
byte inputS[] = Hex.decodeHex(inputSHex.toCharArray());
final JBBPFieldStruct result = sasParser.parse(inputS);
I get:
Exception in thread "main" java.lang.NullPointerException
at com.igormaznitsa.jbbp.compiler.varlen.JBBPOnlyFieldEvaluator.eval(JBBPOnlyFieldEvaluator.java:52)
at com.igormaznitsa.jbbp.JBBPParser.parseStruct(JBBPParser.java:174)
at com.igormaznitsa.jbbp.JBBPParser.parse(JBBPParser.java:489)
at com.igormaznitsa.jbbp.JBBPParser.parse(JBBPParser.java:515)
at Main.main(Main.java:31)
If I replace uint32 with int then it works as expected (until I use a true uint32 value).
could you provide your implementation of uint32? I will make test
Hi, sorry I included a link in the original question: https://gist.github.com/use-sparingly/ac1539784af7ae7569cd50135016cf2c
thank you very much for the report, I have added your case into tests and fixed the case
Thanks for the rapid turn around (and for the excellent project!)