Open xenoterracide opened 3 years ago
Would love to have this as well. Using Dagger and Immutables, which lead to many false positives (or at least, not fixable by me positives).
+1 same with Micronaut generated code. Those have @io.micronaut.core.annotation.Generated
Just wanted to start working on this and found that it has already been done. This issue should be covered by https://github.com/spotbugs/spotbugs/pull/2395 and should therefore be included in the next release.
As far as I can see, the corresponding documentation in docs/filter.rst is missing though. I could add some, are there other places where they would be needed? @hazendaz
@RenovatingDev Not sure where all documentation is missing, please do send PR for anything you find.
I am trying to use the new option, but it does not work.
https://github.com/spotbugs/spotbugs/blob/4.8.0/CHANGELOG.md#added
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter
xmlns="https://github.com/spotbugs/filter/3.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/4.8.0/spotbugs/etc/findbugsfilter.xsd">
<Match>
<Annotation name="javax.annotation.processing.Generated"/>
</Match>
</FindBugsFilter>
seems like it's working for me,
<?xml version="1.0" encoding="UTF-8" ?>
<FindBugsFilter
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://github.com/spotbugs/filter/3.0.0"
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/4.8.0/spotbugs/etc/findbugsfilter.xsd"
>
<Match>
<!-- Returning mutable references, I slightly agree but this is also ludicrous level -->
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" />
<Class name="~.*Test.*" />
</Match>
<Match>
<!-- safe to ignore in tests due to gitattributes -->
<Bug pattern="VA_FORMAT_STRING_USES_NEWLINE" />
<Class name="~.*Test$?.*" />
</Match>
<Match>
<Annotation name="jakarta.persistence.metamodel.StaticMetamodel" />
</Match>
</FindBugsFilter>
Doesn't work for me either. It seems it only works if the class itself has the annotation and won't ignore generated methods with a Generated annotation for example.
Yes, that's correct. That's what the above linked release notes tell. If you want it to match on methods, I guess you should post a separate feature request.
I think that spotbugs should auto ignore (or be easily configurable to) classes/methods/fields decorated with
@javax.annotation.processing.Generated
, also some frameworks don't use this, so honestly I think it should ignore those things if the name of the annotation isGenerated
. Alternatively, maybe just add an option to the exclude/filter config, e.g.