DLS_DEAD_LOCAL_STORE SuppressWarnings FindBugs false positive
Solution 1
More Googling + Experimenting and I finally figured out a way to do this.
Check Section 6
under http://findbugs.sourceforge.net/manual/filter.html .
You need to create your own XML file with all the custom supressions in there.
You'll then need let build.xml file know about this file via findbugs.exclude.filter
<Match>
<Class name="com.foobar.MyClass" />
<Method name="someMethod" />
<Bug pattern="DLS_DEAD_LOCAL_STORE" />
</Match>
No need to add the @SuppressWarnings
tag in the method once this is there in the XML.
Hope this helps someone!
Solution 2
I just had the same problem with this code:
@Test
public void testSomething() {
@SuppressWarnings("unused")
@SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE")
final SomeMockClass mock = new SomeMockClass();
...
}
}
The @SuppressFBWarnings
does not work here.
The solution here was to move the @SuppressFBWarnings
up to the method level:
@Test
@SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE")
public void testSomething() {
@SuppressWarnings("unused")
final SomeMockClass mock = new SomeMockClass();
...
}
}
I like to keep the scope of these annotations as small as possible, so they don't suppress real problems. Here it seems to be necessary to annotate the whole method.
Solution 3
As explained in FindBugs documentation, apparently Sun/Oracle's javac compiler often generates dead stores for final
local variables. These DLS_DEAD_LOCAL_STORE warnings cannot be easily suppressed.
Not sure why the XML filter does work (as in the accepted answer), though.
Comments
-
Garfield almost 2 years
I'm trying to eliminate a false positive for DLS_DEAD_LOCAL_STORE
Here's what I have tried so far:
@SuppressWarnings("DLS_DEAD_LOCAL_STORE")
@edu.umd.cs.findbugs.annotations.SuppressWarnings("DLS_DEAD_LOCAL_STORE")
(based on SuppressWarnings not working on FindBugs)
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "please go away")
based on http://osdir.com/ml/java-findbugs-general/2010-06/msg00017.html
But none of the options is helping. Please advice. Using Eclipse Indigo.