Quick revision
The short answer
JSpecify is a shared standard for Java nullness annotations, agreed by the makers of IDEs, checkers and libraries: @Nullable, @NonNull, @NullMarked and @NullUnmarked. @NullMarked on a package or class makes every unannotated type non-null by default, so we only mark the exceptions. Spring Framework 7 replaced its own org.springframework.lang annotations with JSpecify so that NullAway, IDEs and Kotlin all understand Spring's APIs the same way; the annotations change nothing at runtime.
What to remember
In this answer, we saw that JSpecify is a shared standard for nullness annotations with four of them: @Nullable, @NonNull, @NullMarked and @NullUnmarked. @NullMarked makes unannotated types non-null, so we only mark the nullable exceptions. Spring Framework 7 replaced its own org.springframework.lang annotations with JSpecify so that NullAway, IDEs and Kotlin all read its APIs correctly, and we saw that the annotations change nothing at runtime: tools enforce them at build time.
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.
JSpecify is a shared standard for Java nullness annotations, agreed by the makers of IDEs, checkers and libraries: @Nullable, @NonNull, @NullMarked and @NullUnmarked. @NullMarked on a package or class makes every unannotated type non-null by default, so we only mark the exceptions. Spring Framework 7 replaced its own org.springframework.lang annotations with JSpecify so that NullAway, IDEs and Kotlin all understand Spring's APIs the same way; the annotations change nothing at runtime.
Why this question is asked
For twenty years Java has had many competing @Nullable annotations: JSR 305, JetBrains, Android, Checker Framework, Spring's own. Each tool understood some of them and interpreted them slightly differently, so library authors could never annotate once for everyone. Interviewers ask about JSpecify because Spring Framework 7 and Spring Boot 4 adopted it, which changes how Spring APIs look in our IDE and in Kotlin. In this answer, we will recap the null problem, go through the four annotations, see how @NullMarked changes the default, explain why Spring switched and what Kotlin gains, and be clear about what the annotations do not do.
1A Quick Recap of the Null Problem
In Java, any reference type can hold null, and the type system does not tell us whether a method may return null or whether a parameter accepts it. We find out by reading documentation, or by a NullPointerException in production. Nullness annotations add that missing information to the type: @Nullable String means this may be null, and a plain String in a null-marked scope means it never is.
The information is only useful if tools read it. A checker such as NullAway can then report, at compile time, a dereference of a value that may be null. An IDE can highlight it as we type. Kotlin can turn it into its own nullable and non-null types. For that, everyone has to agree on what the annotations mean, which is the gap JSpecify fills.
2The Four JSpecify Annotations
JSpecify 1.0 defines a small set of annotations in the package org.jspecify.annotations, with precise, documented semantics. @Nullable says a type usage may include null. @NonNull says it may not, which we rarely need to write because of the next annotation. @NullMarked, placed on a package, class, method or module, says that inside this scope unannotated types are non-null. @NullUnmarked switches that default off again for a part of the scope, which is useful while migrating.
| Annotation | Where | Meaning |
|---|---|---|
@NullMarked | package, class, method, module | unannotated types in this scope are non-null |
@Nullable | a type usage | this value may be null |
@NonNull | a type usage | this value is never null (rarely needed when null-marked) |
@NullUnmarked | package, class, method | turn the default off here, nullness unknown |
@NullMarked code we annotate only the exceptions.Notice how little we wrote. Because the package is @NullMarked, id, the return type of summary() and the list itself are non-null without any annotation; we only mark the places where null is allowed. Notice too that JSpecify annotations are type-use annotations: they attach to a specific use of a type, so we can say the list is non-null while its elements may be null. For a qualified type the annotation goes before the simple name, as in java.util.@Nullable List, and for an array, String @Nullable [] means the array itself may be null.
3Why Spring Framework 7 Adopted JSpecify
Spring had its own annotations since Spring Framework 5: org.springframework.lang.Nullable, NonNull, NonNullApi and NonNullFields. They were based on the old JSR 305 meta-annotations, which were never finished as a standard, and they were declaration annotations, which cannot express things like a non-null list of nullable elements. Tools supported them with varying accuracy.
Spring Framework 7, the base of Spring Boot 4, moved the whole framework to JSpecify: packages are @NullMarked and nullable parameters and return types use org.jspecify.annotations.Nullable. The old org.springframework.lang annotations are deprecated. The framework is checked with NullAway during its own build, so the annotations are not just documentation; they are verified. For us, this means that when we call a Spring API from null-marked code, NullAway and the IDE know exactly which results may be null, for example a method that looks up an optional bean or a header that may be absent.
If our own code used Spring's old annotations, the migration is mostly a change of imports plus adding @NullMarked to package-info.java files; check your IDE's migration support and the Spring Framework 7 upgrade notes for details.
4What Kotlin Gains
Kotlin has nullability built into its type system: String and String? are different types. When Kotlin calls Java, it reads nullness annotations to decide which to use. Without them, a Java type becomes a platform type, written String!, and Kotlin trusts the programmer, which means NullPointerExceptions can come back. Recent Kotlin versions understand JSpecify and, by default, treat its annotations strictly, so a Spring method returning @Nullable String appears in Kotlin as String?, and the compiler forces a null check. Non-null types appear as plain String, so Kotlin code no longer needs defensive checks for values that can never be null.
5What the Annotations Do Not Do
It is important to be precise here: JSpecify annotations have no effect at runtime. The JVM does not check them, no exception is thrown when we pass null to a parameter that is non-null by default, and nothing is added to the bytecode except the annotation metadata. All enforcement comes from tools at build time and in the editor: NullAway or the Checker Framework as compiler plugins, IntelliJ IDEA's inspections, and the Kotlin compiler. If we want a runtime guarantee at a boundary, for example in a public library method, we still write Objects.requireNonNull(arg).
6Follow-up questions
Do we need @NonNull at all if we use @NullMarked?
Rarely. Inside a null-marked scope unannotated types are already non-null, so @NonNull is mostly used in unmarked code, or to override a generic type parameter that was declared nullable, for example a type variable T extends @Nullable Object used as non-null in one place.
Is JSpecify tied to Spring?
No. It is an independent project with participants from several companies and tool vendors, released as version 1.0 in 2024. Spring adopted it, and so have other libraries; any Java project can use the small org.jspecify:jspecify dependency.
What happens if a library we call is not annotated?
Its types are unspecified: the checker does not know whether they can be null. NullAway, by default, treats unannotated code optimistically to avoid a flood of warnings, so we get less protection at that boundary. This is one reason Spring's adoption matters: a large part of the code we call is now annotated.
7Conclusion
In this answer, we saw that JSpecify is a shared standard for nullness annotations with four of them: @Nullable, @NonNull, @NullMarked and @NullUnmarked. @NullMarked makes unannotated types non-null, so we only mark the nullable exceptions. Spring Framework 7 replaced its own org.springframework.lang annotations with JSpecify so that NullAway, IDEs and Kotlin all read its APIs correctly, and we saw that the annotations change nothing at runtime: tools enforce them at build time.
Open with
JSpecify is a common standard for nullness annotations in Java, agreed by tool vendors and library authors, because before it every tool had its own @Nullable with slightly different meaning.
Then, if they want more
It has four annotations. @Nullable says a type usage may be null. @NullMarked on a package or class says that every unannotated type in that scope is non-null, so in practice I only annotate the exceptions. @NonNull is rarely needed inside a null-marked scope, and @NullUnmarked switches the default off again, which helps during migration.
They are type-use annotations, so I can say a list is non-null but its elements may be null. Spring Framework 7 moved from its own org.springframework.lang annotations, which were based on the unfinished JSR 305, to JSpecify, marked its packages as null-marked, and checks itself with NullAway.
The benefit for us is that NullAway, IntelliJ and Kotlin all understand Spring's APIs the same way: in Kotlin, a nullable Spring return type shows up as String with a question mark, and a non-null one as plain String.
One thing I always point out is that the annotations do nothing at runtime; enforcement comes from checkers at build time and from the IDE.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 7, Spring Boot 4, Spring Framework 5
- 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
- Apache Maven guides, Gradle user manual
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 "What are JSpecify annotations and why did Spring Framework 7 adopt them?": https://scrivio-interview-library.netlify.app/java/code-quality-tools/304decad38/