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?
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 {}