简体   繁体   English

如何正确使用@SuppressFBWarnings忽略printStackTrace findbugs警告

[英]How to use @SuppressFBWarnings correctly to ignore printStackTrace findbugs warning

In my junit 4 test code I am using test rules that contain code like this: 在我的junit 4测试代码中,我正在使用包含如下代码的测试规则:

catch (Throwable t) {
   t.printStackTrace();
   throw t;
}

Findbugs complains about this, and rightfully so - this should not be done in our production code. Findbugs对此有所抱怨,这是正确的-我们的生产代码中不应这样做。 In this instance, however, I think the usage is justified, and I try to use the @SuppressFBWarnings annotation to silence findbugs. 但是,在这种情况下,我认为用法是合理的,我尝试使用@SuppressFBWarnings注释使findbugs静音。 However, neither 但是,两者都没有

@SuppressFBWarnings
private void warmUp() throws Throwable {

nor 也不

@SuppressFBWarnings("IMC_IMMATURE_CLASS_PRINTSTACKTRACE")
private void warmUp() throws Throwable {

nor 也不

@SuppressFBWarnings({"IMC_IMMATURE_CLASS_PRINTSTACKTRACE"})
private void warmUp() throws Throwable {

have the desired result. 有理想的结果。

How do I use @SuppressFBWarnings correctly to surpress the warning? 如何正确使用@SuppressFBWarnings取消警告?

By using the following gradle dependency for the FindBugs annotations: 通过对FindBugs批注使用以下gradle依赖关系:

compile 'com.google.code.findbugs:findbugs-annotations:3.0.1'

Here is what should work: 这是应该起作用的方法:

@SuppressFBWarnings(value = "IMC_IMMATURE_CLASS_PRINTSTACKTRACE", justification = "Document why this should be ignored here")
private void warmUp() throws Throwable {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM