I have the simple code below for testing the NonNull annotations in IntelliJ.
Then I go to:
IntelliJ -> File -> Settings -> Inspections -> Probable bugs -> Constant conditions & exceptions
and I set-up Severity: As error.
Doing so, it marks the line “print(null);” as an error as expected.
However, executing IntelliJ -> Build -> Rebuild project,
it works and it does not show any error and it does not show any warning.
Why is so? Why IntelliJ does not complain when building the project?
How to see a list of the NonNull violations?
Is there a way to enforce IntelliJ to fail the compilation if it finds a NonNull violation?
Note: IntelliJ is set-up to take into account the firebug annotations (as by default);
moreover, using the org.jetbrains.annotations.NotNull produces exactly the same result.
src/main/java/test/Hello.java
package test;
import edu.umd.cs.findbugs.annotations.NonNull;
public class Hello {
static public void print(@NonNull Object value) {
System.out.println("value: " + value.toString());
}
static public void main(String[] args) {
if (args.length > 0) {
print(args[0]);
} else {
print(null);
}
}
}
and the pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hello</groupId>
<artifactId>hello</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.7</version>
</dependency>
</dependencies>
</project>
Code inspections are not compiler errors, at the moment there is no way to fail compilation if there is some problem reported by inspection, even if the severity level is set to
error.To get the project wide results use
Analyze|Inspect Codewith the appropriate inspection profile.There is similar feature request in IDEA project issue tracker, but it doesn’t seem to be very popular (almost 2 years old and zero votes).