PDA

View Full Version : [CLOSED] BaseModelData NPE silently



Kutu
30 Jul 2008, 1:31 PM
The following line is in BaseModelData get(String property):



return map == null ? null : (X) map.get(property);
This seems to fail silently because if the return value of map.get(property) is null, converting to (X) will fail (my guess)

Maybe it should return null as well if map.get() is null before type-casting to (X).

zaccret
31 Jul 2008, 4:43 AM
I don't think so. A cast from null value to X won't fail.

darrellmeyer
2 Aug 2008, 8:57 AM
zaccret is correct:


public void onModuleLoad() {
ModelData m = new BaseModelData();
String s = m.get("foo");
if (s == null) {
System.out.println("no problem");
}
}