Is there a way to suppress FindBugs from generating warnings on code generated by static weaving?

StackOverflow https://stackoverflow.com/questions/20124985

Frage

I'm getting what I think are false positives from FindBugs (2.0.2) and Sonar (3.7.3) on code that is being generated via static weaving of EclipseLink (2.5.1) JPA entities. Specifically, I am seeing multiple occurrences of

ES_COMPARING_PARAMETER_STRING_WITH_EQ
Comparison of String parameter using == or != in com.test.domain.MyEntity._persistence_set(String, Object)

and

URV_INHERITED_METHOD_WITH_RELATED_TYPES
Inherited method com.test.domain.MyEntity._persistence_get(String) returns more specific type of object than declared

Is there a way to eliminate these warnings for the code generated by EclipseLink without having to globally disable the rules or exclude analysis on the entities entirely?

War es hilfreich?

Lösung

Very good question! Since your issues originate with FindBugs, you can use FindBugs exclusion filters to address this. Especially, take a look at the <Method> exclusion. You can specify a regex that matches the method names of your getters and setters in the entity classes, such as

<Method name="~_persistence_[gs]et" />

Such a filter file can be used by all forms of FindBugs, including the Eclipse plugin and SonarQube. For example, using the SonarQube ant task, you can set the property sonar.findbugs.excludesFilters to the absolute path to the FindBugs exclusion file.

Andere Tipps

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top