java.lang.NullPointerException What ?

ALAA MURAD alaamurad at gmail.com
Mon Sep 1 22:37:30 PDT 2008


Hi everyone ,

I'm just going crazy from the java.lang.NullPointerException , have
any one at sun or the openJDK community thought about adding more
information to this error ?

for example :

package test;
/**
*
* @author alaa
*/
public class NullHell {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

Integer a=50;
Integer b=100;
System.out.println("A+B:"+ ( a +b));
}

}
======This code is working fine=========
A+B:150


Now change the a to null like this:
Integer a=null;

Now, rerun the appliction and sure you get this :

Exception in thread "main" java.lang.NullPointerException
at test.NullHell.main(NullHell.java:22)
Java Result: 1

And here you can't tell where is the error . (which one is null a or b ?)

========================

Wouldn't be nice if they could tell something like this

Exception in thread "main" java.lang.NullPointerException(A==null)
at test.NullHell.main(NullHell.java:22)

another example like ,
getCusomers().getOrders().getOrderByID(100).getOrderItem(0); , when u
get NullPointerException in such a line, you have to go debug
customers, orders , order Item and so on. You can't tell which method
from those returning the null !

Any thoughts about this ?


And what with this primitive forum that you can't format your code in it !!!



More information about the compiler-dev mailing list