---
title: "Null references: the billion-dollar mistake you still ship"
url: https://erroneo.us/daily/null-billion-dollar-mistake/
description: "Tony Hoare called null his billion-dollar mistake. Why null references crash programs, and how Kotlin, Rust, TypeScript and C# catch them at compile time."
type: daily-entry
section: "Developers"
date_published: 2026-11-15
author: erroneo.us Editors
date_modified: 2026-11-15
publisher: erroneo.us
license: All rights reserved. Quote with attribution and a link.
---

# Null references: the billion-dollar mistake you still ship

> In 2009 the inventor of the null reference called it his billion-dollar mistake. Here's why null keeps crashing production code, and the type-system fixes that turn it into a compile-time error.

*Error of the Day for November 15, 2026 · Developers · by erroneo.us Editors*

- **Wrong:** user = findUser(id); print(user.name)  // assumes a user always comes back
- **Right:** user = findUser(id); if (user != null) print(user.name) else handleMissing()  // or let the type system force the check
- **Memory trick:** If a value can be missing, say so in the type; if the type can't say it, check before you dot.

## What people get wrong

The error is treating a reference as if it always points at something. You call `findUser(id)`, you get back what looks like a user, and you read `.name`. Most days that works. The day the user does not exist, the function returns `null` and the program falls over:

```
Exception in thread "main" java.lang.NullPointerException
TypeError: Cannot read properties of undefined (reading 'name')
TypeError: null has no properties
```

Java documents [NullPointerException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/NullPointerException.html) as being thrown "when an application attempts to use null in a case where an object is required," such as calling a method or reading a field on a null object. MDN lists the browser-specific wordings of the JavaScript version under ["null/undefined has no properties."](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/No_properties) Same bug, different accent.

## Why it happens: the billion-dollar mistake

The null reference has a known inventor. In a talk at QCon London in 2009, the computer scientist Tony Hoare, best known for Quicksort, explained that he introduced null references in the language ALGOL W in the mid-1960s "simply because it was so easy to implement," and called the decision "my billion-dollar mistake" ([InfoQ recording and summary](https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare/)).

The figure is a deliberately rough guess, not an audit. According to InfoQ's show notes, Hoare said nobody knows the real cost, but put it at around a billion: more than a tenth of a billion, less than ten billion. The structural problem is what matters. As the notes summarize it, null became "a member of every type," so every reference variable needs a null check on every use, and nothing in most older languages makes you do that check.

That is the trap. A variable typed as `User` promises a user, but it might actually hold "no user," and the compiler cannot tell the two apart. The bug only shows up at runtime, often far from where the null was produced.

## The fix

Wrong: `val user: User = findUser(id)` ~~// compiles, then crashes when no user exists~~

Right: `val user: User? = findUser(id)` // the ? makes "maybe missing" part of the type; the compiler forces you to handle it

Why: Make absence visible in the type, and the compiler checks it for you.

Modern languages fix this by splitting "a user" from "maybe a user":

- **Kotlin** distinguishes nullable types (`String?`) from non-null ones, and per the [Kotlin docs](https://kotlinlang.org/docs/null-safety.html) catches potential null issues "at compile time rather than runtime." The documented ways to still get an NPE include the not-null assertion operator `!!` and Java interop, which is a hint about where to look first.
- **Rust** represents a value that might be missing with [Option](https://doc.rust-lang.org/std/option/), which is "either `Some` and contains a value, or `None`," and is commonly paired with pattern matching that always accounts for the `None` case.
- **TypeScript** with [strictNullChecks](https://www.typescriptlang.org/tsconfig/strictNullChecks.html) on gives `null` and `undefined` their own types, so you get a type error when you use them where a concrete value is expected. With it off, the docs warn, they are "effectively ignored by the language."
- **C#** has [nullable reference types](https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references): you declare which variables may hold null, and the compiler warns when your code does not match.

## How to check your own code

Turn the strict setting on (`strictNullChecks`, C#'s nullable context) and read the warnings rather than suppressing them. Grep for escape hatches like Kotlin's `!!` or TypeScript's non-null `!`, since each one is a promise the compiler cannot verify. Decide what "not found" means at the API boundary: return an optional type, throw a specific error, or return an empty collection instead of null for lists. And in languages without these tools, check before you dot.

>

Hoare's point was about language design, not careless programmers: if the type system lets every reference be null, null bugs are a matter of when, not if.

## Sources

1. [InfoQ: Null References: The Billion Dollar Mistake (Tony Hoare, QCon London 2009)](https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare/)
2. [Oracle Java SE 21 API: NullPointerException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/NullPointerException.html)
3. [MDN: TypeError: null/undefined has no properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/No_properties)
4. [Kotlin docs: Null safety](https://kotlinlang.org/docs/null-safety.html)
5. [Rust std docs: Module std::option](https://doc.rust-lang.org/std/option/)
6. [TypeScript TSConfig reference: strictNullChecks](https://www.typescriptlang.org/tsconfig/strictNullChecks.html)
7. [Microsoft Learn: Nullable reference types (C#)](https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references)

## Go deeper

- https://erroneo.us/developers/javascript-errors/
- https://erroneo.us/developers/famous-software-bugs/
- https://erroneo.us/developers/python-errors/

---
Source page: https://erroneo.us/daily/null-billion-dollar-mistake/ · More: https://erroneo.us/llms.txt
