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.
find bugs html report in build artifact
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.

findbugs html report for java issues
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.

Suppress warnings 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:




Comments

  1. Thanks for sharing this information with us and it was a nice blog.
    AWS Cloud Support in Delhi

    ReplyDelete
  2. Hi, Amazing you know this article is helping for me and everyone and thanks for sharing information.
    JavaScript Training Course in Delhi

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Thanks for sharing Blog. This Blog is very Helpful. Gnec Media is a leading website design, web development company in Delhi offer custom website development services.


    Web Development Services in Delhi

    ReplyDelete
  5. If you are looking for Apps that are comprehensive, high on visual appeal, intelligent, responsive, and engaging, We are the leading mobile app development company in the UK.

    ReplyDelete
  6. Very useful code for all startups. Please check our new website for best and more informative article Audit firms in dubai
    Economic Substance Dubai

    ReplyDelete
  7. Superb explanation & it's too clear to understand the concept as well, keep sharing admin with some updated information with right examples. Keep update more posts. Nice Article! Thanks for sharing such amazing information.
    SEO Company
    Digital Marketing Service
    Digital Marketing company in Delhi

    ReplyDelete
  8. 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. lawn suits with chiffon dupatta , 2 piece suit online shopping in pakistan

    ReplyDelete
  9. I'm reading a blog on this website for the first time, and I'd like to commend you on the high quality of the content. It's quite well-written. Thank you so much for posting this blog; I will definitely read all of your future writings.

    photographers in Andaman
    photoshoot in havelock Andaman
    photoshoot in Andaman
    pre wedding shoot in Andaman
    Andaman photoshoot
    photoshoot at Andaman

    ReplyDelete
  10. I definitely enjoy every little bit of it and It is a great website. I want to thank you for the content. I learn a lot from your blog. Good job! You guys do a great blog and have some great content. Keep up the good work.
    best hr management software india

    ReplyDelete
  11. Really nice article. Thanks for sharing. Keep share much more. Good Luck.
    best hotels to stay in yercaud

    ReplyDelete
  12. Hi, I am John Smith I am Web Developer, It is an amazing blog thanks for the sharing the blog. Frantic infotech provide the ios e-commerce app development such as an information about software development for costumer service. Frantic infotech also provide the ios education app development . Theve delopment of advanced web applications is Orient Software’s specialty and we will successfully fulfill all your web application development requirements, from small-sized to wider-ranged projects. We Also do work multiple platforms like:
    Flutter app development
    android app development
    react native app development
    Hardware Mobile App Development
    penetration testing
    angularjs web development

    ReplyDelete
  13. This blog will help you to understand a comparison between the Qualities of a FinancialForce
    Developer. Hire FinancialForce Developer starting from $1800/ Monthly.

    ReplyDelete

Post a Comment

Popular posts from this blog

Change Port on a Spring Boot Application when using intelliJ

New Personal Website

How to set up a SQL Server 2008 Local Database