Home » Java » Enterprise Java » Suppress FindBugs Warnings in a Java and Spring Boot Web Application using Gradle

About Chris Anatalio

Chris Anatalio

Chris is a Software Engineer currently working as a consultant for a firm called Ippon Technologies. He attended Virginia
Commonwealth University for a BS in Computer Science. He is active in blogging, social media and open source.

Suppress FindBugs Warnings in a Java and Spring Boot Web Application using Gradle

How to Suppress FindBugs Warnings using Annotations in a +Spring Boot and +Java Application

If your build is breaking because of a FindBugs issue and it is a false-positive or you are unable to resolve the issue because of other considerations, you can add an Annotation to ignore the Findbugs warning.

Update your Gradle Dependencies

You will want to add the following compile time dependency to your build.gradle file.

compile group: ‘findbugs’, name: ‘findbugs’, version: ‘1.0.0’

dependencies {

    compile group: 'findbugs', name: 'findbugs', version: '1.0.0'
}

Get the Findbugs Issue ID

You will need a specific ALL_CAPS identifier so that FindBugs knows what bug to ignore.

Locate the FindBugs Report 

In your build message, you will see a link to the findbugs report:

You can also find the report in your build artifact.  Right-click and open in your preferred browser to view file.

Open the findbugs html report from the build directory

Open the findbugs html report from the build directory

 Open the FindBugs Report

Once you have it, open the Findbugs HTML report in a browser.  It should look like the following.

find-bugs

Find Bugs HTML Report

Get the FindBugs identifier 

Copy and paste the FindBugs identifier.  It should be in ALL_CAPS.

You will use the annotation like this:


@SuppressWarnings(“OUT_OF_RANGE_ARRAY_INDEX”)

Add the Annotation to Your Code

Be sure that the correct findbugs SuppressWarnings annotation is being used.

import edu.umd.cs.findbugs.annotations.SuppressWarnings;

Add Suppress warnings annotation

Add this Suppress warnings annotation above the offending line of code.  There are multiple versions of this annotation.

Be sure to use the specific FindBugs issue ID as a parameter in the annotation.

Be sure to use the annotation specific to findbugs in the package edu.umd.cs.findbugs.annotations.

findbugs-annotation

Use the edu.umd.cs.findbugs.annotation version of @SuppressWarnings

This is the annotation you will want to add above the offending line of code.

@SuppressWarnings("OUT_OF_RANGE_ARRAY_INDEX")

Re-run the Build to Verify that the Warning is being Suppressed

You want to ensure that the warning is being ignored correctly.  You may want to add a TODO as well if you intend to fix the issue at a later point as well or at least track the issues you are suppressing in some way.

Your build should run successfully without issuesmoving forward now.

Further info:

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
Email address:

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz