IntelliJ has a code inspection feature that is designed to prevent null pointer exceptions based on static code analysis - actually a kind of interesting idea, and the folks over at IntelliJ have recommended that the annotations be included in the Java SDK in the future. I noticed this feature when I was cleaning up some code today and found a cryptic error message in the IntelliJ code inspection tool:
Not annotated method overrides method annotated with @NotNullThe community documentation for IntelliJ has a nice explanation of this feature, and there is a Maven repository available. The dependency for version 12 of IntelliJ is the following:
<!-- STATIC CODE INSPECTIONS -->
Adding the @NotNull annotation to my overridden method and to a parameter seems to have cleared up the issue. I'm thinking about using these annotations more in my own code to express my assumptions about which objects are nullable and which should not be null.<dependency><groupId>com.intellij</groupId><artifactId>annotations</artifactId><version>12.0</version></dependency>
Comments
Post a Comment