Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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?

like image 537
thorwinn Avatar asked Dec 24 '22 00:12

thorwinn


1 Answers

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 {}
like image 176
johnmartel Avatar answered Jan 31 '23 03:01

johnmartel