Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Should your organisation adopt null-safety checking (JSpecify plus NullAway or similar) across all Java services? How would you roll it out?

Yes, for most organisations, but gradually rather than by decree. Null-safety checking moves whole classes of NullPointerExceptions to compile time and makes APIs say what they mean, at the cost of annotation work, false positives where our code meets unannotated libraries, and some training. I would roll it out package by package with @NullMarked, starting with new code and shared libraries, take advantage of Spring Framework 7 and other libraries that are already annotated, and measure NPE incidents before and after.

Why this question is asked

NullPointerException is still one of the most common exceptions in Java production logs, and most of them come from a simple misunderstanding between the author of a method and its caller about whether null is allowed. Tools to prevent this exist, but adopting them across dozens of services is an organisational decision with real costs. Interviewers ask this at senior level to see whether we can weigh the benefit honestly, plan an adoption that does not stall delivery, and prove the value afterwards. In this answer, we will look at what the checking buys, what it costs, how to roll it out in stages, why the timing is good now, and how to measure success.

1What Null-Safety Checking Buys Us

The setup is JSpecify annotations in our code plus a checker such as NullAway, which runs as an Error Prone plugin inside the compiler. In a package marked @NullMarked, every type is non-null unless it says @Nullable, and the checker refuses to compile code that dereferences a nullable value without a check, or passes null where it is not allowed.

The first benefit is the obvious one: a large share of NullPointerExceptions become compile errors on the developer's machine instead of incidents in production. The second is less obvious but just as valuable. Every method signature now states whether it can return null, so a reader no longer has to open the implementation or guess. Code reviews stop arguing about defensive null checks, because the checker tells us where they are needed and where they are not. Kotlin services calling our Java libraries also get correct nullable types for free.

2What It Costs

The costs are real and we should state them up front. There is annotation work: someone has to decide, for every public method of a shared library, whether null is allowed. On an existing module, turning on the checker typically produces dozens to hundreds of errors, and fixing them is careful work, not search and replace.

There are false positives at the boundaries. When our code calls a library that is not annotated, the checker does not know what it returns. NullAway treats such code optimistically by default, which means fewer warnings but also less protection; stricter settings mean more noise. Frameworks that inject values by reflection, such as fields set by JPA or by dependency injection, need care, usually through configured annotations that tell the checker those fields are initialised outside the constructor.

And there is training. Developers need to understand the rules, why a local variable makes a check work where a repeated method call does not, and when @Nullable is the honest answer versus a default value. Without that, people reach for @SuppressWarnings and the effort loses its point.

3Rolling It Out Package by Package

The rollout I would propose has four stages. First, a pilot: one team adds JSpecify and NullAway to one service, configured to check only @NullMarked code, and marks two or three packages. The goal is to learn the real cost per package and write down the patterns that come up. Second, new code: from then on, every new package gets a package-info.java with @NullMarked, which costs almost nothing because the code is written with the rules from the start.

Third, shared libraries. These give the best return, because every annotated public method protects all its callers in every service. Fourth, existing service code, package by package, prioritised by where NPEs actually happen. Each package is a small, reviewable change, and @NullUnmarked lets us exclude a hard class temporarily without blocking the rest.

Java
// build: the checker only looks at code that opted in (option names vary by NullAway version)
-Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true
// package-info.java, added one package at a time
@NullMarked
package com.acme.billing.invoices;
import org.jspecify.annotations.NullMarked;
Step throughRolling out null-safety checking
  1. Pilot in one servicemeasure cost per package, collect patterns
  2. Mark all new packages@NullMarked in package-info.java
  3. Annotate shared librariesbiggest return: every caller benefits
  4. Existing code by NPE hot spotsone package per change, @NullUnmarked for hard cases
  5. NPE incidents falling?
    YesContinue and make it the defaultNoReview the configuration and training

5 steps in order. Play them, or step through them one at a time.

The checker is strict from day one, but only on code that opted in.

Notice that the checker is an ERROR from the first day, but only where code has opted in. This avoids the trap of a warnings-only phase that nobody reads. Teams join at their own pace, and once a package is marked it can never regress.

4Why the Timing Is Good Now

Five years ago, the biggest argument against this was the boundary problem: most libraries we call were not annotated, or used incompatible annotations. That has changed. JSpecify 1.0 gave the ecosystem one standard, and Spring Framework 7, the base of Spring Boot 4, annotates its whole API with it and checks itself with NullAway. Other widely used libraries are following. So when our null-marked code calls a Spring API, the checker knows precisely which results may be null, and the false positives at the biggest boundary in a Spring service largely disappear. Upgrading to Spring Boot 4 is a natural moment to start.

5Measuring Whether It Worked

An organisation-wide change should be judged by results. Before the rollout, we count NullPointerException incidents and production errors per service from the error tracker or logs over the last two quarters, for example 40 NPE-related incidents across 30 services. During the rollout we track the share of packages that are null-marked per service. Then we compare: if services with most packages marked show a clear drop in NPEs while others do not, the effort is paying off. We also watch the cost side, such as how often @SuppressWarnings("NullAway") appears and how long developers say fixes take, because a rising suppression count means the rules are not understood or the configuration is wrong.

6Follow-up questions

Should we use the Checker Framework instead of NullAway?

The Checker Framework's nullness checker is more thorough and sound in more cases, but it is slower and needs more annotations, which makes it harder to adopt across many services. NullAway is designed to be fast enough for every compile and to need few annotations, which is why it suits a broad rollout. Some teams use the Checker Framework for a small, critical library.

What about Optional instead of annotations?

Optional is a good return type for methods where absence is a normal result, and it can coexist with annotations. But it does not cover parameters and fields, and wrapping every nullable value would be heavy. Annotations plus a checker cover the whole type system at no runtime cost, so I would use both, with Optional only for return values.

How do we stop teams from just suppressing the errors?

Track suppressions as a metric, require a short comment with each one, and review them in pull requests. More importantly, invest in training and a small internal guide with the common patterns, so that the correct fix is easier than the suppression.

7Conclusion

In this answer, we weighed null-safety checking for a whole organisation. It moves many NullPointerExceptions to compile time and makes APIs clearer, but it costs annotation work, brings false positives at boundaries with unannotated libraries, and needs training. We rolled it out with @NullMarked package by package, starting with new code and shared libraries, noted that Spring Framework 7 and other libraries already ship JSpecify annotations, and planned to measure NPE incidents before and after.

What to say in the interviewAbout 70 seconds aloud

Open with

I would adopt it, but gradually and with measurement. The benefit is that a large class of NullPointerExceptions becomes compile errors, and every signature says whether null is allowed, which makes APIs clearer and reviews simpler.

Then, if they want more

The costs are annotation work on existing code, false positives where we call unannotated libraries or rely on reflection, and training, because if people do not understand the rules they just suppress the errors. So I would run a pilot in one service with NullAway set to error, but only for null-marked code, to learn the cost per package.

Then every new package gets @NullMarked from the start, which is nearly free. Next I would annotate shared libraries, because each annotated public method protects every caller. Existing code follows package by package, prioritised by where NPEs actually happen, with @NullUnmarked for the hard cases.

The timing is good: Spring Framework 7 and Spring Boot 4 are annotated with JSpecify, so the biggest boundary in our services is already covered. Finally I would count NPE incidents before and after, and watch suppression counts, to show whether it paid off.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 7, Spring Boot 4
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.
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 "Should your organisation adopt null-safety checking (JSpecify plus NullAway or similar)...": https://scrivio-interview-library.netlify.app/java/code-quality-tools/a98ca603c0/