Skip to content

Null Safety as in Spring 7 (JSpecify @NullMarked and @Nullable) #62

@magicprinc

Description

@magicprinc

I would like to encourage you to migrate your project from JetBrains nullable annotations to JSpecify.
https://jspecify.dev/

JSpecify is developed collaboratively by major players across the Java ecosystem, aiming to be the unified, open standard for nullness annotations: i.e. Google (Android, Error Prone, Guava), JetBrains (IDEA, Kotlin), OpenJDK team, Spring, Sonar, etc

Spring 7 (Nov. 2025) uses JSpecify and Uber NullAway for ultimate Null Safety
https://spring.io/blog/2025/03/10/null-safety-in-spring-apps-with-jspecify-and-null-away

PS:
Instead of adding @nonnull repeatedly on individual elements, it is better to use @NullMarked at the class or package level. This sets a “non-null by default” policy, meaning all elements are treated as non-null unless explicitly annotated with @nullable. This approach makes the code cleaner and reduces annotation clutter.

https://jspecify.dev/docs/using/
In addition to adopting JSpecify's @nullable and @nonnull annotations, you may also wish to adopt @NullMarked. If your code already annotates all its @nullable types, then you can (with rare exceptions) remove any @nonnull annotations in favor of putting a @NullMarked annotation on the whole class, package, or module.

@NullMarked is similar to JSR-305's @ParametersAreNonnullByDefault and custom @TypeQualifierDefault annotations. Still, @NullMarked differs from those, including in its effect on generics, so you may need to take advantage of your new ability to annotate locations like type arguments (as in Future<@nullable Credentials>). @NullMarked is likely to have an effect closer to what you want, but it may require additional work on your part.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions