Maven Null Annotations
Which null annotations are used within Maven?
Maven 4 provides its own annotations in org.apache.maven.api.annotations.
The following annotation types are relevant for dealing with null values:
The purpose of those annotations is twofold:
- They allow static source code analysis tools to check if developers are missing null checks or passing null for method arguments annotated with
@Nonnull. - They are evaluated at run time by Maven Dependency Injection.
Which classes are using those annotations yet?
All Maven 4 API modules are annotated with aforementioned annotations and it is recommended for plugin developers to use those annotations in their custom Maven 4 mojos as well.
Which compile time tools support those custom annotations
Not all static source code analysis tools support custom annotations (like Maven Null annotations). The following tools/IDEs are known to work:
- NullAway does not require specific configuration to support Maven Null annotations.
- IntelliJ IDEA requires explicit configuration of the annotation class names.
- Eclipse requires explicit configuration of the annotation class names.
On the other hand some other tools don't or only partially support custom Null annotations as they rely on some built-in lists of fully qualified names (FQN) for those annotations:
- SonarQube is having a hardcoded list of FQNs of supported Null annotations, however there seem to be partial support for meta-annotations
- SpotBugs is having a hardcoded list of FQNs of supported Null annotations
How is Maven evaluating those annotations at run time?
Maven Dependency Injection is checking for injections having @Nullable annotations and in this case won't fail if injection is not possible.
The same applies to Google Guice leveraged with Sisu.
Why is Maven not using standard annotations?
There exist multiple libraries for null annotations, probably most common these days is JSpecify and also some dormant libraries from the past like JSR 305. In order to allow Maven null annotations to coexist with any other standard annotations in any version in the Maven classpath we took the decision to come up with custom annotations in our own namespace. That way the API does not have any 3rd party dependencies.



