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

Java 如何正确使用@SuppressFBWarnings忽略printStackTrace findbugs警告,java,findbugs,printstacktrace,Java,Findbugs,Printstacktrace,在junit 4测试代码中,我使用的测试规则包含以下代码: catch (Throwable t) { t.printStackTrace(); throw t; } Findbugs对此抱怨,这是理所当然的——这不应该在我们的生产代码中进行。然而,在本例中,我认为这种用法是合理的,我尝试使用@SuppressFBWarnings注释使findbugs静音。然而,两者都不是 @SuppressFBWarnings private void warmUp() throws Throw

在junit 4测试代码中,我使用的测试规则包含以下代码:

catch (Throwable t) {
   t.printStackTrace();
   throw t;
}
Findbugs对此抱怨,这是理所当然的——这不应该在我们的生产代码中进行。然而,在本例中,我认为这种用法是合理的,我尝试使用@SuppressFBWarnings注释使findbugs静音。然而,两者都不是

@SuppressFBWarnings
private void warmUp() throws Throwable {
也不是

也不是

达到预期的效果


如何正确使用@SuppressFBWarnings来超越警告?

通过对FindBugs注释使用以下渐变依赖项:

compile 'com.google.code.findbugs:findbugs-annotations:3.0.1'
以下是应该采取的措施:

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

第二种选择是正确的。你重新编译了吗?谢谢你的反馈。我无法让它工作,目前使用的是伐木机。但是,如果我需要处理类似的问题,它可以帮助我知道什么应该起作用。
compile 'com.google.code.findbugs:findbugs-annotations:3.0.1'
@SuppressFBWarnings(value = "IMC_IMMATURE_CLASS_PRINTSTACKTRACE", justification = "Document why this should be ignored here")
private void warmUp() throws Throwable {}