Misnomer: NullPointerException

Java does not have pointers. Variables are of primitive or reference type. So it uses references. Then why is there a NullPointerException?

A NullPointerException is always thrown when the null reference is used when there has to be a valid object. The JLS never uses the term “null pointer” except in NullPointerException. The value of null is called “the null reference”. But the class NullPointerException exists since version 1.0 of Java. The author is unascribed.

The JVM uses pointers internally. Much of the code of the JVM is written in C or other languages that use pointers. But the faulty use of such an actual null pointer would probably crash the JVM. The NullPointerException is purely about Java code.

The name should be NullReferenceException. They simply can’t fix it any more.

The whole concept of null pointers/references was a bad idea. Tony Hoare, inventor of the null reference, even apologized for it:
http://qconlondon.com/london-2009/presentation/Null+References:+The+Billion+Dollar+Mistake

With the annotations of JSR 305 it is possible to prevent null reference exceptions at compile time. But many libraries do not use it yet.

Leave a Reply

Your email address will not be published. Required fields are marked *