Search code examples
javaintellij-ideaannotationsfindbugsnull-check

Can IntelliJ auto-generate code to null-check arguments when using @ParametersAreNonnullByDefault annotation on package


I like the feature where IntelliJ can automatically generate code to check at runtime for null on each argument/parameter passed to a method.

This feature is enabled in Preferences > Build, Execution, Deployment > Compiler > Add runtime assertions for notnull-annotated methods and parameters (checkbox). The neighboring Configure annotations button configures which annotation package.

I am trying to set my not-null annotation at the package level. Example:

@ParametersAreNonnullByDefault
package work.basil.ticktock.backend.data;

import javax.annotation.ParametersAreNonnullByDefault;

My question is: Which, if any, of these "Configure annotations" work the generate code for the @ParametersAreNonnullByDefault annotation discussed here and found here?

The null-checks are indeed working within the code editor, generating warnings. But I want runtime-checking as provided by the checkbox shown in this screenshot.

Screenshot of IntelliJ Preferences > Build, Execution, Deployment > Compiler > Add runtime assertions for notnull-annotated methods and parameters (checkbox)


Solution

  • Please follow/comment the duplicated feature request already created at YouTrack, but not yet implemented: https://youtrack.jetbrains.com/issue/IDEA-164347. Thank you.