Could produce NullPointer??

Code inspection says a nullpointer could be thrown at the comment....maybe my brain just isn't working?

private static boolean areSame(Object one, Object two){
if(one == null ^ two == null)
return false;

if(one == null && two == null)
return true;

return one.equals(two); //nullpointer here?
}

3 comments
Comment actions Permalink

Didn't seem so to my eyes.

Output from simple test:

areSame - null , null: true
areSame - null , x: false
areSame - x , null: false
areSame - x , x: true
areSame - x , y: false

No npe thrown.


0
Comment actions Permalink

that is what i thought, but idea outsmarts me sometimes :)

0
Comment actions Permalink

Yes, this seems a bug, if my brains works right not having its usual cup of
coffee:))
"charles decroes" <spam@decroes.com> wrote in message
news:29319089.1059697325741.JavaMail.javamailuser@localhost...

Code inspection says a nullpointer could be thrown at the comment....maybe

my brain just isn't working?
>

private static boolean areSame(Object one, Object two){
if(one == null ^ two == null)
return false;

>

if(one == null && two == null)
return true;

>

return one.equals(two); //nullpointer here?
}

>


0

Please sign in to leave a comment.