Course contentsShow
← Java
Lesson 1754 of 2,87037. Optional for Null SafetyFree lesson

The Billion-Dollar Mistake: null References

Understand why null references cause NullPointerExceptions and why Tony Hoare called them his "billion-dollar mistake."

The Billion-Dollar Mistake: null References

You'll learn why null is considered one of computing's most expensive design decisions and how it leads to runtime crashes.

What's the Problem with null?

In Java, any reference type can hold the special value null, meaning "no object." This seems convenient—how else would you represent "nothing"? But it creates a fundamental problem: you can't tell by looking at a type whether it might be null.

When you see String name, it could be a valid String object, or it could be null. If you call a method on a null reference, Java throws a NullPointerException at runtime:

String message = null;
int length = message.length(); // 💥 NullPointerException!

Why "Billion-Dollar"?

Tony Hoare, who invented null references in 1965, later apologized for it, calling it his "billion-dollar mistake." Why? Because NullPointerExceptions have:

  • Crashed countless applications
  • Required billions of dollars in debugging time
  • Forced programmers to write defensive null-checks everywhere
  • Made code harder to read and maintain

The Core Issue

The problem isn't null existing—it's that the type system doesn't distinguish between nullable and non-nullable references. A Consumer<String> might receive a null String, but the type signature doesn't tell you. You only discover the problem when your program crashes.

Think of it like electrical outlets: if some outlets were secretly dead but looked identical to working ones, you'd constantly check every outlet before plugging anything in. That's what null does to your code.

Key Takeaway: null causes NullPointerExceptions because Java's type system doesn't distinguish nullable from non-nullable references, forcing runtime checks instead of compile-time safety.