Quick revision
The short answer
I would treat nullness as a long, incremental quality investment rather than a project. Adopt the standard JSpecify annotations now, so code already states its nullness in the form that tools, Kotlin and, later, compiler-checked null-restricted types can use; enforce them on new code first and migrate hot or risky modules gradually as they change; measure NPE incidents and static analysis findings per module; and avoid any big-bang rewrite, since the payoff comes from steady progress tied to normal work.
What to remember
In this answer, we planned for nullness over a decade: adopt JSpecify annotations now because they capture nullness decisions that tools, Kotlin and future null-restricted types can all use, enforce them on new code first and migrate hot, risky and shared modules gradually as they change, measure coverage and NPE incidents per module, and avoid big-bang rewrites, treating nullness as an incremental quality investment tied to normal change.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would treat nullness as a long, incremental quality investment rather than a project. Adopt the standard JSpecify annotations now, so code already states its nullness in the form that tools, Kotlin and, later, compiler-checked null-restricted types can use; enforce them on new code first and migrate hot or risky modules gradually as they change; measure NPE incidents and static analysis findings per module; and avoid any big-bang rewrite, since the payoff comes from steady progress tied to normal work.
Why this question is asked
Null references cause a steady stream of production failures in every large Java codebase, and the industry is moving towards a fix: Kotlin made nullability part of its type system years ago, the JSpecify group agreed on standard annotations, Spring and other major libraries have adopted them, and the OpenJDK's Valhalla work includes proposals for null-restricted types in the Java language itself. For a company with millions of lines of Java, the question is not whether nullness will become checkable but how to be ready without wasting effort. Interviewers ask this to see whether a senior leader can plan across a decade of uncertain language changes. In this answer, we will look at where the ecosystem is heading, explain why annotations now are the right bet, plan the rollout, cover Kotlin interop and measurement, and explain why a big-bang rewrite is the wrong move.
1Where the Ecosystem Is Heading
Tony Hoare introduced null references in ALGOL W in 1965 and later called them his billion-dollar mistake, because a value that can be absent without the type saying so leads to errors that the compiler cannot catch. Languages have since answered in two ways. Kotlin builds nullability into the type: String cannot be null, String? can, and the compiler enforces the difference. Java, constrained by compatibility, has relied on annotations and external checkers.
Two developments change the picture. JSpecify, a group of companies and projects including Google, JetBrains, Uber and the Spring team, published version 1.0 of standard nullness annotations in 2024, ending years of competing @Nullable annotations. And Project Valhalla in OpenJDK has proposed null-restricted and nullable types, such as String! and String?, as part of its work on value classes. At the time of writing these are proposals or previews rather than a final language feature, so the exact syntax, timing and semantics are uncertain (check your version).
- Today: annotationsJSpecify
@NullMarkedand@Nullable, used by Spring Framework 7 - Today: build-time checkersNullAway, IDE inspections, Kotlin compiler
- Next: wider library adoptionmore of the dependency graph is annotated
- Later: language supportnull-restricted types from Valhalla work, timing uncertain
4 layers, from the top down. Step through them one at a time.
Each layer builds on the information captured by the one above it.
2Why Annotations Now Are the Right Bet
The valuable and expensive part of nullness is not the syntax; it is the knowledge of which values may be absent. Someone has to look at each API and decide whether getMiddleName() may return null. Annotations capture that decision today, in a form tools already check. If and when Java gains null-restricted types, migrating code whose nullness is already declared is largely mechanical, and tools can assist, because the decisions are already made. Code that never declared its nullness will need all those decisions made then, under pressure.
The annotations also pay off immediately, which is what makes the investment safe even if language support takes years. NullAway in the build catches null dereferences at compile time; IntelliJ highlights them as people type; and Spring Framework 7's APIs are already annotated, so our code gets precise information about the framework's nullness for free.
Choosing JSpecify specifically matters, because older annotation sets, javax.annotation, JetBrains, Checker Framework, Android and Spring's own, differ slightly in meaning. Standardising on one set across the company avoids a second migration later.
3The Rollout: New Code First, Then Gradual Migration
The plan has stages that fit normal work. First, the platform team adds JSpecify and NullAway to the shared build configuration, with NullAway set to check only packages marked @NullMarked. Second, new modules and packages are @NullMarked from day one, which costs very little because the code is written with nullness in mind. Third, existing modules are migrated in priority order: the ones with the most NPE incidents, the ones on critical paths such as payments, and shared libraries used by many teams, because annotating a library helps every consumer.
Everything else is migrated as it is changed. When a team does substantial work in a package, it marks the package @NullMarked and fixes the findings as part of that change. Over several years, the actively changed code, which is where most bugs occur, becomes covered, while stable code that nobody touches stays as it is, which is acceptable because it is not where new NPEs are coming from.
- Is it new code?Yes@NullMarked from the startNoLook at its risk
- Many NPE incidents or critical path?YesMigrate it as planned workNoLook at its activity
- Being changed substantially?YesAnnotate it in the same changeNoLeave it for now
- Track coverage and NPEsper module, every quarter
4 steps in order. Play them, or step through them one at a time.
4Kotlin Interop and Mixed-Language Teams
If teams mix Java and Kotlin, annotations pay off at once. Without them, Kotlin sees Java types as platform types, which its messages write as String!, where the compiler does not know whether null is possible and leaves the risk to the programmer. With JSpecify annotations, the Kotlin compiler reads them and treats annotated Java types as properly nullable or non-null, so Kotlin's null safety extends across the language boundary.
That makes shared Java libraries the highest-value targets in a mixed organization: annotating one library used by forty Kotlin services improves the safety of all of them without any change in those services.
5Measuring Progress and Avoiding a Big Bang
We measure two things per module. The input measure is coverage: the share of packages marked @NullMarked and the number of open NullAway findings, which shows the work is happening. The outcome measure is NullPointerException incidents and error counts in production, taken from error metrics tagged by exception type and service. Comparing them shows whether annotated modules really have fewer NPEs, which keeps the investment honest and helps decide where to go next.
A company-wide rewrite to annotate everything, or to move every service to Kotlin for null safety, would be a mistake. It would stop feature work for months, touch stable code that rarely fails, and create a large risk of regressions, all to gain protection in places where it is least needed. Nullness is a quality investment whose value comes from steady, incremental progress tied to the code that is actively changing, and a plan built that way survives changes in priorities, staff and even the eventual language design.
6Follow-up questions
What if Java's final null-restricted types differ from JSpecify?
That is likely in details, but the core information, which references may be null, is the same. Code annotated with JSpecify can be migrated with tooling, and the JSpecify group includes people working on the JDK, which makes alignment more likely. The risk of waiting is larger than the risk of a later mechanical migration.
Should we just move to Kotlin instead?
For some teams Kotlin is a good choice for other reasons, but rewriting millions of lines of working Java for null safety alone is not worth the cost and risk. Annotations bring much of the benefit to existing Java code, and they also improve Kotlin interop for teams that do adopt Kotlin.
Who owns this over a decade?
A platform or architecture group owns the shared build configuration, the guide and the dashboards, and reviews progress every quarter. Product teams own the migration of their modules. Revisiting the plan when a relevant JDK feature reaches preview or final is part of the group's job.
7Conclusion
In this answer, we planned for nullness over a decade: adopt JSpecify annotations now because they capture nullness decisions that tools, Kotlin and future null-restricted types can all use, enforce them on new code first and migrate hot, risky and shared modules gradually as they change, measure coverage and NPE incidents per module, and avoid big-bang rewrites, treating nullness as an incremental quality investment tied to normal change.
Open with
The expensive part of null safety is deciding, for every API, which values may be absent, and that work is the same whether we express it with annotations today or with null-restricted types later.
Then, if they want more
So I would start now with the standard JSpecify annotations, NullMarked on packages and Nullable where needed, and NullAway in the shared build, configured to check only marked packages. That pays off immediately with build-time checks and IDE warnings, and Spring Framework 7 already uses JSpecify, so the framework's nullness is visible to us.
When Java gets null-restricted types through the Valhalla work, whose exact form and timing are still uncertain, annotated code can be migrated largely mechanically. For the rollout, new code is NullMarked from day one, then we prioritise modules with the most NPE incidents, critical paths and shared libraries, and everything else gets annotated when a team changes it substantially.
If we have Kotlin teams, annotations matter right away, because Kotlin reads them and stops treating our Java types as platform types, so shared libraries are high-value targets. I would measure coverage and NPE incidents per module each quarter.
And I would avoid any big-bang rewrite or language migration for this alone; nullness is an incremental investment tied to normal change.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 7
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Tony Hoare called null references his billion-dollar mistake. Kotlin built nullness into...": https://scrivio-interview-library.netlify.app/java/exceptions/bf585c2e80/