Quick revision
The short answer
Spring Framework 7 declares the nullness of its APIs with JSpecify annotations, @NullMarked and @Nullable, which replace Spring's own org.springframework.lang annotations, now deprecated. Build-time checkers such as NullAway and IDEs read them to warn when we pass or dereference a possible null, and Kotlin maps them to nullable and non-null types. A team can mark its own packages @NullMarked and enable a checker gradually, remembering that the annotations add no runtime checks; they only inform tools.
What to remember
In this answer, we saw that Spring Framework 7 declares nullness with JSpecify @NullMarked and @Nullable, replacing its deprecated org.springframework.lang annotations. The annotations are precise type-use annotations that tools read: NullAway fails the build on possible null misuse, IDEs warn while we type, and Kotlin turns them into nullable and non-null types. They add no runtime checks. A team migrates its own annotations, marks packages @NullMarked gradually and enables a checker for marked code only.
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.
Spring Framework 7 declares the nullness of its APIs with JSpecify annotations, @NullMarked and @Nullable, which replace Spring's own org.springframework.lang annotations, now deprecated. Build-time checkers such as NullAway and IDEs read them to warn when we pass or dereference a possible null, and Kotlin maps them to nullable and non-null types. A team can mark its own packages @NullMarked and enable a checker gradually, remembering that the annotations add no runtime checks; they only inform tools.
Why this question is asked
NullPointerException is the most common runtime failure in Java code, and many of them come from a simple misunderstanding: we did not know a method could return null. Spring has annotated its APIs for nullness since Framework 5, but with its own annotations that few tools understood fully. Framework 7 moves to JSpecify, a standard set of annotations agreed by several tool and library vendors. Interviewers ask about it because it changes how Spring code is checked and how Kotlin sees Spring, and because teams can use the same approach in their own code. In this answer, we will recap the problem, see what JSpecify annotations mean, look at how tools and Kotlin use them, and plan how a team adopts them.
1A Quick Recap of the Null Problem
In Java, any reference type can hold null, and the type system does not say whether it might. A method declared as String findName(long id) may return a name or null, and only its documentation, if any, tells us which. If we guess wrong, the program fails at runtime with a NullPointerException, often far from where the null came from.
Nullness annotations make that information part of the code, so tools can check it. Spring has done this since Framework 5 with @Nullable, @NonNull and @NonNullApi in the org.springframework.lang package. The trouble was that every library had its own set, from JSR 305 to JetBrains to Checker Framework, with slightly different meanings.
2What JSpecify Annotations Mean
JSpecify defines a small set of annotations in org.jspecify.annotations with precise, agreed meanings. @NullMarked on a package, class or module says that inside it, types are non-null unless marked otherwise. @Nullable on a type says null is allowed there. @NullUnmarked switches the default off again for legacy code, and @NonNull exists for rare cases inside unmarked code.
Notice the last line. JSpecify annotations are type-use annotations, which means they attach to a type wherever it appears, including type arguments and array components. That is more precise than the old declaration annotations, and it is one reason Spring switched. With @NullMarked, the common case needs no annotation at all, so code stays readable.
3How Tools, IDEs and Kotlin Use Them
The annotations do nothing at runtime. There is no generated null check, and a method marked non-null can still return null if its code is wrong. Their value comes from the tools that read them.
| Reader | What it does | When |
|---|---|---|
| NullAway (Error Prone plugin) | fails the build on possible null misuse | compile time |
| IntelliJ IDEA and other IDEs | warnings while typing | editing |
| Kotlin compiler | maps to String? or String in Kotlin | compile time |
| JVM at runtime | nothing: no checks are added | never |
With Spring's APIs annotated, a checker knows, for example, that a method returning @Nullable String must be checked before use. Spring builds its own code with NullAway, so the annotations are verified, not just declared. For Kotlin, the effect is the most visible: a Spring method returning @Nullable String appears as String?, and one in a marked package appears as String, so the Kotlin compiler enforces null handling instead of treating every Java type as a platform type of unknown nullness. Check your Kotlin version for how strictly it reports JSpecify mismatches.
4What a Team Should Do in Its Own Code
If our code uses Spring's org.springframework.lang annotations, we replace them with the JSpecify ones; they are deprecated in Framework 7. Then we start marking our own packages. The gradual path is to add @NullMarked to new packages first, then to existing packages one at a time, fixing the warnings each time, and to enable NullAway in a mode that only checks marked code.
So the build fails exactly where a null could reach a dereference, and only in code we have opted in. The fix is usually a check, an Optional at an API boundary, or realising that the method should never return null and changing its signature.
5Follow-up questions
How would you roll out NullAway on a large existing codebase?
Gradually and package by package. First add Error Prone and NullAway with only marked code checked, so nothing changes yet. Then mark new modules @NullMarked from day one. For existing code, pick the packages with public APIs or frequent null bugs, mark one, fix its errors, and merge, so each change is small. Legacy code that cannot be fixed yet stays unmarked or gets @NullUnmarked. Make NullAway an error in CI for marked packages so they stay clean, and track the number of marked packages as progress.
Do the annotations replace Objects.requireNonNull?
No. The annotations help tools catch mistakes in code we compile, but values can still arrive as null from reflection, deserialisation, or callers that do not use a checker. At public boundaries, an explicit requireNonNull still gives a clear failure at the right place.
Why did Spring not just use Optional everywhere?
Optional is useful for return values that are often absent, but it adds an allocation, does not fit fields or parameters well, and would break existing APIs. Annotations describe nullness without changing signatures, so they can be added to a large existing API compatibly.
6Conclusion
In this answer, we saw that Spring Framework 7 declares nullness with JSpecify @NullMarked and @Nullable, replacing its deprecated org.springframework.lang annotations. The annotations are precise type-use annotations that tools read: NullAway fails the build on possible null misuse, IDEs warn while we type, and Kotlin turns them into nullable and non-null types. They add no runtime checks. A team migrates its own annotations, marks packages @NullMarked gradually and enables a checker for marked code only.
Open with
In Framework 7 Spring moved its null-safety annotations to JSpecify. Instead of Spring's own org.springframework.lang annotations, which are now deprecated, its packages are @NullMarked, meaning types are non-null by default, and anything that can be null is annotated with JSpecify's @Nullable.
Then, if they want more
JSpecify is a shared standard agreed between tool and library vendors, and its annotations are type-use annotations, so they can say precisely that a list is non-null but its elements may be null. The important thing to know is that they add nothing at runtime. Their value is in tools.
NullAway, an Error Prone plugin that Spring uses on its own code, can fail the build when we dereference something that may be null, and IDEs show the same warnings while we type.
For Kotlin it is a big improvement: Spring APIs now appear as String or String question mark, instead of platform types, so the Kotlin compiler enforces null handling.
In our own code, I would replace any Spring nullness annotations with JSpecify ones, mark new packages @NullMarked from the start, enable NullAway in a mode that only checks marked code, and then mark existing packages one at a time, fixing errors as we go, so the rollout never blocks the team.
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
- Spring Framework reference, Core technologies
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 "Spring Framework 7 moves its null-safety annotations to JSpecify. What does this give...": https://scrivio-interview-library.netlify.app/spring-boot/spring-framework-evolution/d98734f6ec/