XTend null safe throws NullPointerException -


i porting template code xtend. @ point have type of condition handling in test case:

@test def xtendiftest() {     val obj = new fd     if (true && obj?.property?.isnotnull) {         return     }     fail("not passed") }  def boolean isnotnull(object o) {     return o != null } class fd {  @accessors  string property } 

this works expected property null , test fail "not passed" message. simple change in return type of isnotnull method boolean (wrapper):

def boolean isnotnull(object o) {     return o != null } 

fails nullpointerexception. examining generated java code can see xtend using intermediate boolean object expression , cause of npe. missing point of xtend null safe operator (?.) or can't use method after operator?

thanks.

the operator behaves properly. exception thrown because of usage of boolean in if-expression, requires auto-unboxing.

if try following:

@test def xtendiftest() {     val boolean obj = null     if (obj) {         return     }     fail("not passed") } 

you run nullpointerexception.

this consistent java language specification (https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.8) - when auto-unboxing required can yield nullpointerexception:

@test public void test() {     boolean value = null;     if (value) { // warning: null pointer access: expression of type boolean null requires auto-unboxing         // dead code     } } 

hope helps.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -