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. Very nice post here thanks for it .I always like and such a super contents of these
    post.Excellent and very cool idea and great content of different kinds of the valuable
    information's
    Server Management Company in Delhi
    Live Streaming Company in Delhi
    seo company in delhi

    ReplyDelete
  3. smart outsourcing solutions is the best outsourcing training
    in Dhaka, if you start outsourcing please
    visit us: Freelancing training in bangladesh
    Outsourcing training in dhaka
    Outsourcing training in bangladesh

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

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

    ReplyDelete
  6. 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
  7. 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
  8. 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
  9. We are well established IT and outsourcing firm working in the market since 2013. We are providing training to the people ,
    like- Web Design , Graphics Design , SEO, CPA Marketing & YouTube Marketing.Call us Now whatsapp: +(88) 01537587949
    : Digital marketing training
    Free bangla sex video:careful
    good post Freelancing Training in bangladesh

    ReplyDelete
  10. Thanks for Sharing This Article.It is very so much valuable content.
    DevOps Training
    DevOps Online Training

    ReplyDelete
  11. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    devops online training
    best devops online training
    top devops online training

    ReplyDelete
  12. Enjoyed reading your blog. Please check my latest post on the chartered accountant in Dubai  and let me know what you think.

    ReplyDelete
  13. 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
  14. 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
  15. Tecocraft is a renowned mobile app development agency in the US, providing world-class mobile app development services to worldwide clients at affordable prices. Tecocraft holds a proficient team of talented mobile app developers who have expertise in creating functionality-rich, feature-loaded, and scalable Android/iOS mobile applications to let your business portable on mobile. Our dedicated mobile app developers make use of cutting-edge technologies and advanced tools by choosing the right development frameworks based on your custom business requirements.

    ReplyDelete
  16. Thanks For Sharing such a wonderful article the way you presented is really amazing
    Best Software Training Institutes

    ReplyDelete

Post a Comment

Popular posts from this blog

Change Port on a Spring Boot Application when using intelliJ

How to set up a SQL Server 2008 Local Database

Building Microservices with JHipster