How to use @SuppressFBWarnings correctly to ignore printStackTrace findbugs warning
Asked Answered
M

1

5

In my junit 4 test code I am using test rules that contain code like this:

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

Findbugs complains about this, and rightfully so - this should not be done in our production code. In this instance, however, I think the usage is justified, and I try to use the @SuppressFBWarnings annotation to silence 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?

Marienthal answered 6/10, 2016 at 14:17 Comment(2)
The second option is correct. Did you recompile?Soileau
Thank you for the feedback. I couldn't make it work and used loggers for the moment. But it helps me to know what should work, if I need to deal with a similar problem.Marienthal
P
11

By using the following gradle dependency for the FindBugs annotations:

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 {}
Partida answered 12/4, 2017 at 2:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.