如何忽略Findbugs的bug
如何忽略Findbugs的bug
除了用xml的形式去忽略一些文件和bug。最好用的还是注解:
下面的方法会有MT_CORRECTNESS和STYLE的bug。注解忽略方法为:
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
value = {"MT_CORRECTNESS", "STYLE"},
justification = "I know what I'm doing")
public JdbcTemplate get(String datasourceName) {
JdbcTemplate jdbcTemplate = TEMPLATE.get(datasourceName);
if (jdbcTemplate == null) {
synchronized (this) {
if (jdbcTemplate == null) {
jdbcTemplate = createTemplate(datasourceName);
TEMPLATE.put(datasourceName, jdbcTemplate);
}
return jdbcTemplate;
}
}
return jdbcTemplate;
}
需要添加以下依赖
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
关注我的公众号