Issue with nullable NumericProperty and internalization

17 views
Skip to first unread message

Thomas

unread,
Apr 26, 2018, 12:13:35 AM4/26/18
to CodenameOne Discussions
I have a PropertyBusinessObject Vehicle Object defined with:

``` 
public final LongProperty<Vehicle> id = new LongProperty<>("id", new Long(-1)); 
public final IntProperty<Vehicle> height = new IntProperty<>("height");
public final IntProperty<Vehicle> length = new IntProperty<>("length");
public final IntProperty<Vehicle> width = new IntProperty<>("width");
public final IntProperty<Vehicle> weight = new IntProperty<>("weight");

...

public Vehicle() {
id.setNullable(true);
height.setNullable(true);
length.setNullable(true);
width.setNullable(true);
weight.setNullable(true);
}
```

The problem I have is that, when I want to internalize one of this stored Vehicle object with a null IntProperty, I end up with an error like that:

```
java.lang.NullPointerException: height can't be null
at com.codename1.properties.NumericProperty.set(NumericProperty.java:87)
at com.codename1.properties.MyPropertyIndex$1.internalize(MyPropertyIndex.java:285)
at com.codename1.io.Util.readObject(Util.java:693)
at com.codename1.io.Util.readObject(Util.java:664)
at com.codename1.io.Storage.readObject(Storage.java:261)
```

I don't realy know how to solve this issue (exept by forcing my IntProperty to have a default value, like I did for `id`. But I would like to keep it null if possible as I also bind these properties to ui and a null Intproperty value would directly convert to an empty String in a TextField whereas a default -1 of 0 value for example, would be directly displayed as it is). 
I assume that the internalization process don't call the Vehicle() default constructor, which is why my setNullable(true) are not called in this case. Is there another way I could define my IntProperty as nonNullable to avoid this?

Shai Almog

unread,
Apr 26, 2018, 12:22:44 AM4/26/18
to CodenameOne Discussions
A bug in the code, we'll fix it for Friday. It seems I wrote nullable instead of !nullable at some point...

Thomas

unread,
Apr 26, 2018, 12:30:55 AM4/26/18
to CodenameOne Discussions
Yes just found the typo in the set method of the NumericProperty class too. Thanks ;)
Reply all
Reply to author
Forward
0 new messages