Java 强制IntelliJ在非null冲突时编译失败
下面是在IntelliJ中测试非空注释的简单代码 然后我去: IntelliJ->文件->设置->检查->可能的错误->恒定条件和异常 我设置了严重性:作为错误 这样做,它会将行“print(null);”标记为预期的错误。 但是,在执行IntelliJ->Build->Rebuild项目时, 它工作正常,不显示任何错误,也不显示任何警告 为什么会这样?为什么IntelliJ在构建项目时不抱怨 如何查看非空冲突列表 如果IntelliJ发现非空冲突,是否有办法强制IntelliJ使编译失败Java 强制IntelliJ在非null冲突时编译失败,java,intellij-idea,findbugs,Java,Intellij Idea,Findbugs,下面是在IntelliJ中测试非空注释的简单代码 然后我去: IntelliJ->文件->设置->检查->可能的错误->恒定条件和异常 我设置了严重性:作为错误 这样做,它会将行“print(null);”标记为预期的错误。 但是,在执行IntelliJ->Build->Rebuild项目时, 它工作正常,不显示任何错误,也不显示任何警告 为什么会这样?为什么IntelliJ在构建项目时不抱怨 如何查看非空冲突列表 如果IntelliJ发现非空冲突,是否有办法强制IntelliJ使编译失败 注
注意:IntelliJ设置为考虑firebug注释(默认情况下); 此外,使用org.jetbrains.annotations.NotNull会产生完全相同的结果
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);
}
}
}
以及pom.xml文件:
<?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>
4.0.0
你好
你好
1
net.sourceforge.findbugs
注释
1.3.2
net.sourceforge.findbugs
jsr305
1.3.7
代码检查不是编译器错误,目前,如果检查报告了一些问题,即使严重性级别设置为error
,也无法使编译失败
要获得项目范围内的结果,请使用适当的检查配置文件使用分析
|检查代码
IDEA中有项目问题跟踪程序,但它似乎不太受欢迎(几乎有2年历史,没有投票权)。你可以让Maven失败构建。这种情况改变了吗?有没有办法通过Checkstyle(特别是)检查使构建在IntelliJ中失败?也许通过运行外部工具?