Adding an exclusive filter for <static initializer> in findbugs

I want to avoid showing the following error in my bug report:

DM_NUMBER_CTOR: method calls inefficient Number constructor; use static value instead

The problem is that this happens in groovy-generated code files, so I can't control the source code, so I want to exclude it and add it to my exclusion filter.

I don't want to add a class explicitly (since I am creating an API that many tools will use, I want my filter to be generic). I would not like to completely remove this error from the type report, I would really like to exclude this error only if it occurs in the methods of the static initializer. Any ideas? I tried the filter below but no luck, maybe someone has an idea?

<Match>
    <Method name="~.*static initializer.*" />
    <Bug pattern="DM_NUMBER_CTOR" />
</Match>

      

Here is the "stacktrace" FindBugs in this case:

In the class net.milanaleksic.cuc.tools.sound.SoundPlayerTool In the method net.milanaleksic.cuc.tools.sound.SoundPlayerTool. () The method is called new Long (long) Should call Long.valueOf (long) instead of In SoundPlayerTool.groovy

+2


source share


1 answer


I would guess how the static initializer code in the method would report <clinit>

. Could you try installing a filter <Method name='&lt;clinit&gt;'/>

? (which is pretty much <clinit>

, but with XML escaping). Completely untested, just some random thoughts.

My hint was this part of http: // findbugs \ .googlecode \ .com & sa = N & cd = 2 & ct = rc & l = 125 "> some internal FindBugs tests:



 String methodName = m.getMethodName();
 ...
 if (...  methodName.equals("<clinit>")) ) ...

      

I'm not sure, but I think the same method name ( <clinit>

) is mentioned if errors do happen ...

+4


source







All Articles