NullPointerException

14 views
Skip to first unread message

yangru...@gmail.com

unread,
Jan 20, 2013, 8:37:58 PM1/20/13
to java2...@googlegroups.com
When an argument of some function is null, it will throw TypeError not NullPointerException.
public void test(){
    try{
          Boolean.TRUE.compareTo(null);
         } catch(NullPointerException){
                  System.out.println("NPE");
         }
}
It will output TypeError:Unable to get value of the property "valueOf": object is null or undefined
        

Sebastian Gurin

unread,
Jan 22, 2013, 9:27:26 AM1/22/13
to java2...@googlegroups.com
I think this error can be easy fixed. Boolean.compareTo is defined at code.google.com/p/java2script/source/browse/trunk/sources/net.sf.j2s.java.core/src/java/lang/Boolean.js#76

I would fixed it to be :

Clazz.overrideMethod (Boolean, "compareTo",
function (b) {
if(b==null)throw new NullPointerException();
return (b.value == this.valueOf () ? 0 : (this.valueOf () ? 1 : -1));
}, "Boolean");


But I won't since I'm not sure how can this impact... Renjian ?
> --
> You received this message because you are subscribed to the Google Groups "Java2Script" group.
> To post to this group, send email to java2...@googlegroups.com.
> To unsubscribe from this group, send email to java2script...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msg/java2script/-/KIsYxSEUVBIJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


--
Sebastian Gurin <sgu...@softpoint.org>
Reply all
Reply to author
Forward
0 new messages