Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Java chose to add nullness and other properties as optional annotations checked by tools, rather than in the core type system as Kotlin did. What does that mean for long-term code quality strategy, and what would you standardise across the company?

Because Java treats nullness as optional annotations checked by external tools, the guarantee is only as strong as our build configuration: code that no checker runs on, or that uses a different annotation set, gets no protection, unlike Kotlin where the compiler enforces it everywhere. So we would standardise one annotation set (JSpecify) and one checker, enforce it in CI on new code and widen it to legacy code gradually, follow the OpenJDK work on null-restricted types without depending on it, and weigh Kotlin interop and hiring when deciding how far to go.

Why this question is asked

At the level of a whole company, nullness is not a coding style question; it is a reliability strategy. The way the language handles null decides how much of the safety we must build ourselves with tools, how consistent it will be across hundreds of repositories, and how it interacts with teams writing Kotlin. Interviewers ask this of principal-level engineers to see whether they can reason about a language design choice and turn it into standards that hold for years. In this answer, we will compare the two models, see what optional checking really guarantees, look at how fragmentation creeps in, decide what to standardise, and consider the future of Java's own type system and the Kotlin question.

1A Quick Recap of the Two Models

In Kotlin, nullness is part of every type. String can never hold null and String? can, and the compiler refuses to dereference a String? without a check. Every Kotlin file is checked, always, because there is no way to turn it off. At the boundaries where Kotlin code can be called from Java, the compiler even inserts small run-time checks on parameters, so a null passed in from Java fails immediately with a clear message.

In Java, a reference type always allows null as far as the language is concerned. Nullness is added from outside: annotations such as JSpecify's @Nullable and @NullMarked describe the intent, and a pluggable checker such as NullAway or the Checker Framework, run during compilation, enforces it. The JDK designers chose this route because changing the meaning of every existing type would have broken billions of lines of code, while annotations can be adopted one package at a time.

Nullness in Kotlin and in Java
PropertyKotlinJava with annotations
Where nullness livesIn the type systemIn annotations read by tools
Who enforces itThe compiler, alwaysA checker, if the build runs it
Unannotated codeDoes not existUnspecified, usually trusted
Run-time checksInserted at public boundariesNone unless written by hand
AdoptionAll or nothing per fileGradual, package by package

2What Optional Checking Really Guarantees

The consequence of the Java model is that the guarantee belongs to the build, not to the language. If a module's build runs NullAway in error mode over @NullMarked packages, we get close to Kotlin's safety inside that module. If another module never enabled the checker, its @Nullable annotations are only documentation. If a third uses a different checker with slightly different rules, the same code may pass in one and fail in the other.

Even in a fully checked module, a few holes remain by design. Values from unannotated libraries are usually trusted to be non-null. Reflection-based frameworks, such as a JSON mapper creating an object, can leave a non-null field null because they never run through checked code. And Java checkers insert no run-time checks, so a null that slips in is discovered at the dereference, possibly far from where it entered. So the honest answer to a manager who asks whether we are null-safe is: in these modules, against these sources of data, yes; elsewhere, not yet.

3How Fragmentation Creeps In

Left alone, a large organisation drifts into several systems at once. One team uses JSR 305 annotations because an old library pulled them in, another uses JetBrains annotations because the IDE suggested them, a third uses Spring's own, and the shared libraries mix all three. Each tool interprets them differently: one treats a parameter annotation as covering array elements, another does not, and none of them agree on what an unannotated type means.

The cost shows up at the boundaries. A library annotated with one set gives no help to a consumer whose checker only reads another. Kotlin may see a platform type, meaning unknown nullness, instead of String?. So fragmentation does not just waste effort; it quietly removes the safety at exactly the places where teams depend on each other's code.

4What We Would Standardise

The standard has three parts. First, one annotation set: JSpecify, because its semantics are written down, its annotations are TYPE_USE so they work inside generics, and Spring, Kotlin, NullAway and IntelliJ read it. Second, one default checker and one configuration, published in the platform's build plugin so teams do not copy settings by hand: NullAway for everyday builds, with the Checker Framework allowed for libraries that need stronger guarantees. Third, a rule for where the check applies.

For that rule we use a ratchet, a policy that only ever tightens. New packages start with @NullMarked and the checker in error mode. Existing modules run the checker as warnings, and once a module reaches zero warnings it switches to errors and cannot go back. We report, per repository, the share of packages that are null-marked and checked, which turns a vague quality goal into a number that rises every quarter.

Java
// platform build plugin, applied to every Java module
options.errorprone {
check("NullAway", isNewOrClean(project) ? CheckSeverity.ERROR : CheckSeverity.WARN)
option("NullAway:OnlyNullMarked", "true") // only @NullMarked code is checked; check your NullAway version
}
// quarterly report (example): payments 92% marked, search 40% marked, legacy-crm 5% marked
Step throughThe nullness ratchet for a module
  1. New packagestarts @NullMarked, checker as errors
  2. Existing modulechecker runs as warnings
  3. Zero warnings?
    YesSwitch the module to errorsNoFix warnings during normal work
  4. Report the share checkedper repository, every quarter

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

5Planning for Language-Level Nullness Without Betting on It

OpenJDK is working on putting nullness into the type system itself. As part of Project Valhalla, a draft JEP proposes null-restricted and nullable types, written with markers such as String! and String?, first as a preview feature. If it ships, Java would gain some of what Kotlin has, including run-time checks the JVM can rely on for optimisation. But the design and the timeline can still change, and preview features cannot be used in production code we must keep compiling for years.

So we plan for it without depending on it. JSpecify annotations express the same idea, non-null by default inside a marked scope, so code annotated today should migrate mechanically to whatever syntax eventually arrives. We keep a small group following the JEPs and early-access builds, and we write down the migration path as a future recipe, not as a dependency of today's plan (check the current status of the JEP before quoting it).

6Weighing Kotlin Interop and Hiring

There is an alternative way to get compiler-enforced nullness today: write new services in Kotlin. For an organisation that already runs some Kotlin, this is a real option, and well-annotated Java libraries make it better, because Kotlin turns JSpecify annotations into proper nullable and non-null types. That is a strong reason to annotate shared Java libraries even if most services stay in Java.

But switching languages costs more than tooling. Hiring pools, training, code review skills, build times and on-call familiarity all change. For a company of mostly Java engineers, my recommendation would be to keep Java as the default, invest in annotations and checkers until most active code is checked, and allow Kotlin where a team has the skills and a clear benefit. We decide how far to invest by measuring the outcome: the count of NullPointerExceptions in production incidents before and after a module becomes checked tells us whether the effort is paying back.

7Follow-up questions

Is a nullness checker worth the build time?

For NullAway, usually yes: it runs inside normal compilation and typically adds a small percentage to compile time, while a single production NullPointerException can cost hours. The Checker Framework is more thorough but noticeably slower, so we reserve it for libraries where the stronger guarantee matters.

What do you do about frameworks that set fields by reflection?

We treat those types as a boundary. Request and entity classes are validated at the edge, for example with Bean Validation's @NotNull, or modelled as records with checks in the compact constructor, so a null produced by deserialisation fails at the point of entry rather than deep inside checked code.

Would you require Kotlin for new services instead?

Not as a company-wide rule. Kotlin gives enforced nullness, but it changes hiring, training and tooling for every team. I would allow it where teams choose it, and make sure our shared Java libraries are annotated with JSpecify so both languages get accurate nullness at the boundary.

8Conclusion

In this answer, we saw that Java's choice of optional annotations and external checkers makes null safety a property of the build rather than the language, so unchecked or differently checked code gets no guarantee. We standardised one annotation set and one checker configuration, enforced them with a ratchet in CI on new code and gradually on legacy code, planned for OpenJDK's null-restricted types without depending on them, and weighed Kotlin interop and hiring when deciding how far to invest.

What to say in the interviewAbout 80 seconds aloud

Open with

Kotlin put nullness in the type system, so every file is checked and the compiler even adds runtime checks at public boundaries. Java chose annotations plus pluggable checkers, mainly so existing code would not break.

Then, if they want more

The consequence for strategy is that in Java, safety depends on build configuration. A module that runs NullAway in error mode over NullMarked packages is close to Kotlin; a module with no checker gets nothing, and annotations there are just documentation.

Mixed annotation sets make it worse, because tools disagree on meaning, and the safety disappears at the boundaries between teams.

So I would standardise three things: JSpecify as the one annotation set, NullAway as the default checker shipped in the platform build plugin, and a ratchet: new packages start NullMarked with errors, existing modules start with warnings and switch to errors once clean, and we report the checked share per repository.

I'd follow the Valhalla work on null-restricted types, but not depend on a preview feature; JSpecify code should migrate mechanically if it lands. Finally I'd weigh Kotlin honestly: annotated Java libraries help Kotlin consumers a lot, but switching languages changes hiring and training, so I'd keep Java as default and measure production NPEs to see if the investment pays.

About this answer

Last updated
12 November 2026
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 "Java chose to add nullness and other properties as optional annotations checked by...": https://scrivio-interview-library.netlify.app/java/annotations/c60378cac3/