Closed escamoteur closed 4 years ago
I got an bool cannot be null Exception the moment I did a Field() annotation. In my case I wanted to add a processor.
The source of the exception was the code in instantiater.dart from line 195:
instantiater.dart
String encodeTo = name; String decodeFrom = name; bool nullable = globalNullable; FieldProcessorInfo processor; if (annot != null) { dontEncode = annot.getField('dontEncode').toBoolValue() ? true : dontEncode; <- here came the exception dontDecode = annot.getField('dontDecode').toBoolValue() ? true : dontDecode; encodeTo = annot.getField('encodeTo')?.toStringValue() ?? encodeTo; decodeFrom = annot.getField('decodeFrom')?.toStringValue() ?? decodeFrom; nullable = annot.getField('isNullable').toBoolValue() ?? nullable; processor = _parseFieldProcessor(annot.getField('processor')); }
I wonder how this could have worked in the last time at all because if anno did not contain dontEncode and dontEncode you always would get this exception because null.toBoolValue == null my fix now is this here:
anno
dontEncode
null.toBoolValue == null
if (annot != null) { dontEncode = annot.getField('dontEncode').toBoolValue() ?? false ? true : dontEncode; dontDecode = annot.getField('dontDecode').toBoolValue() ?? false ? true : dontDecode; encodeTo = annot.getField('encodeTo')?.toStringValue() ?? encodeTo; decodeFrom = annot.getField('decodeFrom')?.toStringValue() ?? decodeFrom;
I guess this could made more readable if we give up some of the concise format.
Cheers Thomas
I got an bool cannot be null Exception the moment I did a Field() annotation. In my case I wanted to add a processor.
The source of the exception was the code in
instantiater.dart
from line 195:I wonder how this could have worked in the last time at all because if
anno
did not containdontEncode
anddontEncode
you always would get this exception becausenull.toBoolValue == null
my fix now is this here:I guess this could made more readable if we give up some of the concise format.
Cheers Thomas