Adding exclusive filter for <static initializer> in findbugs
I want my findbugs report not show the following error:
DM_NUMBER_CTOR: Method invokes ineffici开发者_如何学运维ent Number constructor; use static valueOf instead
The problem is that this happens in groovy-generated code files, so I can't control the source code - that is why I want to exclude it and add it to my exclude filter.
I do not want to add explicitly class (since I make API that many tools will use, I want my filter to be generic). I would not like to completely remove this bug from the report by type, I would really like to only exclude this bug from appearing if it happenned in "static initializer" methods. Any idea? I tried the filter below but no luck, maybe somebody has better idea?
<Match>
<Method name="~.*static initializer.*" />
<Bug pattern="DM_NUMBER_CTOR" />
</Match>
Here is the "stacktrace" of FindBugs in that case:
In class net.milanaleksic.cuc.tools.sound.SoundPlayerTool In method net.milanaleksic.cuc.tools.sound.SoundPlayerTool.() Called method new Long(long) Should call Long.valueOf(long) instead In SoundPlayerTool.groovy
I would guess the static initializer code would be reported as taking place in method called <clinit>
. Could you try setting a <Method name='<clinit>'/>
filter? (which is pretty much <clinit>
but XML-escaped). Totally untested, just some random thoughts.
My clue was this part of http://findbugs\.googlecode\.com&sa=N&cd=2&ct=rc&l=125">some FindBugs internal tests:
String methodName = m.getMethodName();
...
if (... methodName.equals("<clinit>")) ) ...
I am not sure but I think the same method name (<clinit>
) is mentioned if the bugs actually happen...
精彩评论