<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Static Code Analysis &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/static-code-analysis/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Fri, 06 Jan 2023 17:19:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>Static Code Analysis &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>Suppressing FindBugs Warnings</title>
		<link>https://myshittycode.com/2013/10/25/suppressing-findbugs-warnings/</link>
					<comments>https://myshittycode.com/2013/10/25/suppressing-findbugs-warnings/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Fri, 25 Oct 2013 14:31:53 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[FindBugs]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Static Code Analysis]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=184</guid>

					<description><![CDATA[<p>PROBLEM FindBugs is one of the many great static code analysis tools that I use everyday. However, the generated report may usually contain a few false positives that forces me to weave through them whenever I rerun my build on Jenkins. For example, I&#8217;m using Google Guava to construct my equals(...) and hashCode():- FindBugs will [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2013/10/25/suppressing-findbugs-warnings/">Suppressing FindBugs Warnings</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>FindBugs is one of the many great static code analysis tools that I use everyday. However, the generated report may usually contain a few false positives that forces me to weave through them whenever I rerun my build on Jenkins.</p>



<p>For example, I&#8217;m using <a href="http://code.google.com/p/guava-libraries/wiki/CommonObjectUtilitiesExplained" target="_blank" rel="noopener">Google Guava</a> to construct my <code>equals(...)</code> and <code>hashCode()</code>:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
public class Person {
    private String firstName;
    private String lastName;
    private Long age;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Person other = (Person) o;

        return Objects.equal(firstName, other.firstName) &amp;amp;&amp;amp;
               Objects.equal(lastName, other.lastName);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(firstName, lastName);
    }

    // getters and setters
}
</pre></div>


<p>FindBugs will produce a <code>EQ_UNUSUAL</code> warning with the following description:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
myproject.Person.equals(Object) is unusual&amp;lt;/code&gt;
&amp;lt;code&gt;
&amp;lt;/code&gt;
&amp;lt;code&gt;This class doesn&#039;t do any of the patterns we recognize for checking
that the type of the argument is compatible with the type of the this
object. There might not be anything wrong with this code, but it is
worth reviewing.
</pre></div>


<h2 class="wp-block-heading">SOLUTION</h2>



<p>There are 2 known ways that I know to suppress these warnings. One way is to create FindBugs filter files, which I find very tedious. The other way is to use FindBug&#8217;s annotations to do so, which is what I&#8217;m going to show here.</p>



<p>First, we need to include the neccessary dependency:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;dependency&gt;
    &lt;groupId&gt;net.sourceforge.findbugs&lt;/groupId&gt;
    &lt;artifactId&gt;annotations&lt;/artifactId&gt;
    &lt;version&gt;1.3.2&lt;/version&gt;
&lt;/dependency&gt;
</pre></div>


<p>Next, we annotation <code>equals(...)</code> to suppress that specific warning:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; highlight: [6,7]; title: ; notranslate">
public class Person {
    private String firstName;
    private String lastName;
    private Long age;

    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = &quot;EQ_UNUSUAL&quot;,
                                                      justification=&quot;Implemented using Google Guava&quot;)
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Person other = (Person) o;

        return Objects.equal(firstName, other.firstName) &amp;amp;&amp;amp;
               Objects.equal(lastName, other.lastName);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(firstName, lastName);
    }

    // getters and setters
}
</pre></div>


<p>That&#8217;s it&#8230; it&#8217;s that simple.</p>



<p>Yes, I know there&#8217;s this ugly FindBugs dependency in my code. However, I&#8217;ll take that any day so that I&#8217;m getting a cleaner report from FindBugs. I can also be absolutely sure that I have reviewed the generated warnings and decided that they are safe to be ignored.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2013/10/25/suppressing-findbugs-warnings/">Suppressing FindBugs Warnings</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2013/10/25/suppressing-findbugs-warnings/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">184</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Disk

Served from: myshittycode.com @ 2026-02-18 08:51:01 by W3 Total Cache
-->