Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Your organisation wants to adopt nullness annotations across many repositories. Options include JSpecify, JSR 305, and framework-specific ones. How do you choose and roll this out?

We would standardise on JSpecify, because it is a cross-vendor set of TYPE_USE annotations with defined semantics that Spring, Kotlin, NullAway and IntelliJ all understand, while JSR 305 was never finalised and its javax.annotation package clashes with other jars. We mark packages @NullMarked so unannotated types mean non-null, roll out module by module with NullAway or the Checker Framework starting in warning mode, and annotate the public APIs of shared libraries first.

Why this question is asked

NullPointerException is still one of the most common production failures in Java services, and nullness annotations are the cheapest way to move those failures from production to the compiler. The hard part in a large organisation is not writing @Nullable; it is choosing one set of annotations that every tool reads the same way and getting dozens of teams to adopt it without stopping their work. Interviewers ask this at senior level to hear a real decision and a rollout plan. In this answer, we will compare the candidate annotation sets, see how @NullMarked changes the default, choose a checker, plan the rollout, and deal with third-party libraries that are not annotated.

1A Quick Recap: What Nullness Annotations Do

Java's type system does not say whether a reference can be null. A method returning Customer may return a customer or null, and only the documentation, if any, tells us which. Nullness annotations add that missing piece: @Nullable Customer means the value may be null, and a non-null type means it never is. A checker, a tool run during compilation, then reports any place where code dereferences a nullable value without checking it or passes null where it is not allowed.

The annotations alone do nothing at run time. Their value depends entirely on tools reading them, and that is why choosing which annotations to use is a decision with long-lasting effects: every IDE, checker, framework and language that reads them must agree on what they mean.

2Comparing the Options

There are three families to choose from. JSR 305 annotations, usually from the com.google.code.findbugs:jsr305 jar, were very popular, but the JSR was never finalised, so their meaning was never formally defined. They also live in the javax.annotation package, which other jars use too; on the module path that is a split package, the same package in two modules, which Java refuses to load.

Framework-specific annotations, such as Spring's older org.springframework.lang.Nullable, JetBrains annotations or Android's, work well inside their own ecosystem but tie our libraries to that vendor, and each tool interprets them slightly differently. JSpecify is a joint effort by Google, JetBrains, Uber, the Spring team, Oracle and others to define one set: @Nullable, @NonNull, @NullMarked and @NullUnmarked, all TYPE_USE annotations with a written specification. It reached 1.0 in 2024, and Spring Framework 7 uses it for its own APIs (check your version for the details of the move).

Choosing a nullness annotation set
OptionSemanticsMain problem
JSpecifySpecified, TYPE_USE onlyNewer, some tools still adding support
JSR 305Never finalisedjavax.annotation split package conflicts
Framework-specificDefined by one vendorTies shared libraries to that vendor

The decision is not close. JSpecify is the only option with defined semantics, broad tool support and no packaging problems.

3Making Non-Null the Default With @NullMarked

If we had to write @NonNull on every type, nobody would adopt the annotations. JSpecify avoids that with @NullMarked. Placed on a package, a class or a module, it says that within that scope every type without an annotation is non-null. We only mark the exceptions with @Nullable.

Java
// src/main/java/com/acme/billing/package-info.java
@NullMarked
package com.acme.billing;
import org.jspecify.annotations.NullMarked;
// in com.acme.billing
public interface CustomerRepository {
Customer save(Customer c); // never null in, never null out
@Nullable Customer findById(String id); // may return null
List<@Nullable String> legacyCodes(); // the list is non-null, elements may be null
}

Notice that legacyCodes() shows why TYPE_USE matters: we can say the list is never null but its elements may be. Code outside a @NullMarked scope stays unspecified, which tools treat leniently. That gives us a natural boundary for the rollout: one package at a time moves from unspecified to marked.

4Choosing the Checker and Rolling Out by Module

For the checker, NullAway is the usual choice for a large organisation. It runs as an Error Prone plugin during normal compilation, adds only a small amount of build time, and understands JSpecify and @NullMarked. The Checker Framework is more thorough, for example about generics, but slower and stricter, so it suits critical libraries rather than every service.

We start in warning mode so builds keep passing while teams see the problems, then switch each module to errors once it is clean.

Java
// build.gradle.kts, using the net.ltgt.errorprone plugin
tasks.withType<JavaCompile>().configureEach {
options.errorprone {
check("NullAway", CheckSeverity.WARN) // ERROR once the module is clean
option("NullAway:OnlyNullMarked", "true") // check only @NullMarked code; check your NullAway version
}
}
Step throughRolling out nullness checks
  1. Pick JSpecify and one checkerwrite it in the platform guide
  2. Annotate shared library APIsmost consumers benefit first
  3. Enable NullAway as warningsper module, builds keep passing
  4. Is the module clean?
    YesSwitch to errors and add @NullMarkedNoFix warnings in normal work
  5. New packages start @NullMarkedthe default for new code

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

The order matters as much as the tool. We annotate the public APIs of shared libraries first, because one annotated client library helps every team that calls it: their IDE and checker immediately see which return values may be null. Then services adopt @NullMarked package by package, and new packages start marked from day one. We track the share of packages marked and the warnings per module on a dashboard, so progress is visible without forcing a deadline.

5Checking Kotlin and Spring Compatibility

Kotlin reads nullness annotations from Java code and turns them into Kotlin types. With JSpecify, a @Nullable String return becomes String? in Kotlin, and a @NullMarked package makes plain types non-null String, instead of the unknown platform type String!. Recent Kotlin versions report JSpecify mismatches as errors by default, so annotating a library can turn Kotlin consumers' warnings into compile errors; we test with our Kotlin services before publishing (check your Kotlin version).

Spring also reads nullness annotations, for example to decide whether an injection point or a request parameter is optional. Since Spring Framework 7 supports JSpecify, our annotations and Spring's agree. Before the rollout we run one Kotlin service and one Spring service against the first annotated library, because those are the two places where an annotation can change behaviour or break a build.

6Follow-up questions

How do you handle third-party libraries without annotations?

Their types stay unspecified, and NullAway by default trusts them, assuming they return non-null, which is convenient but not safe. For the few calls that really can return null, I wrap the library in a small adapter in our code that returns @Nullable types or Optional, so the uncertainty is handled in one place. NullAway also supports library models to declare nullness for specific methods, and the Checker Framework uses stub files for the same purpose. For widely used libraries, upstream JSpecify support is often already in progress.

Why not use Optional everywhere instead of annotations?

Optional is good for return values that may be absent, and many teams use it there. But it costs an allocation, it does not work for fields, parameters or collection elements, and it cannot describe existing APIs without changing them. Annotations describe nullness everywhere, at no run-time cost, and keep existing signatures.

What about existing JSR 305 annotations in the codebase?

We migrate them mechanically, for example with OpenRewrite recipes that rewrite imports to JSpecify, and keep the old jar only until the last module moves. In the meantime the checker can be told to recognise both sets, so nothing is lost during the transition.

7Conclusion

In this answer, we chose JSpecify because it is a cross-vendor set of TYPE_USE annotations with defined semantics, while JSR 305 was never finalised and conflicts on the module path. We used @NullMarked to make non-null the default, picked NullAway as the everyday checker, rolled it out module by module starting with warnings and with the public APIs of shared libraries first, and checked Kotlin and Spring compatibility before publishing annotated libraries.

What to say in the interviewAbout 80 seconds aloud

Open with

I would pick one standard, and today that is JSpecify. It's a cross-vendor specification with defined semantics, the annotations are TYPE_USE so they work in generics and arrays, and Spring, Kotlin, NullAway and IntelliJ all understand it.

Then, if they want more

JSR 305 was never finalised, so its meaning is fuzzy, and its javax.annotation package conflicts with other jars on the module path. Framework-specific annotations would tie our shared libraries to one vendor. The key feature is NullMarked: on a package or module it makes every unannotated type non-null, so we only write Nullable where null is allowed.

For checking, I'd use NullAway as an Error Prone plugin because it is fast enough for every build, and reserve the Checker Framework for critical libraries. The rollout goes module by module. First the public APIs of shared libraries, because that helps every consumer.

Then NullAway in warning mode per module, switching to errors once a module is clean, and new packages start NullMarked. Before publishing an annotated library, I'd test it with a Kotlin service, since Kotlin turns these annotations into nullable types and can start failing builds, and with Spring, which reads nullness for things like optional injection. Third-party libraries without annotations get thin adapters or library models.

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.
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 "Your organisation wants to adopt nullness annotations across many repositories. Options...": https://scrivio-interview-library.netlify.app/java/annotations/f8f9eebf02/