jpa - SonarQube (Sonar) + EclipseLink: incorrect error 'Comparison of String parameter using == or !=' -
i have following class, using eclipselink jpa:
package my.package; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.sequencegenerator; import javax.persistence.version; import my.package.api.address; @entity(name = "address") @sequencegenerator(name = "sequence", sequencename = "seq_address") public class addressjpaentity implements address { @id @generatedvalue(strategy = generationtype.sequence, generator = "sequence") private long id; @version private long version; private string street; public addressjpaentity() { } public addressjpaentity(string street) { this.street = street; } @override public long getid() { return id; } public long getversion() { return version; } public void setversion(long version) { this.version = version; } @override public string getstreet() { return street; } @override public void setstreet(string street) { this.street = street; } }
when sonarqube-run, lot of following (incorrect) errors:
bad practice - comparison of string parameter using == or !=
this code compares java.lang.string parameter reference equality using == or != operators. requiring callers pass string constants or interned strings method unnecessarily fragile, , leads measurable performance gains. consider using equals(object) method instead.
findbugs | es_comparing_parameter_string_with_eq comparison of string parameter using == or != in my.package.addressjpaentity._persistence_set(string, object)
for now, solved setting issues false positive, add more similar classes in future , don't want each time.
how can make sonar not mark these errors, without using 'false positive' time?
please check this post solution. shows how create exclusion filter findbugs.
in case, you'll want ignore es_comparing_parameter_string_with_eq
warnings.
i still think it's incorrect use ==, though, apparently, that's not can help.
Comments
Post a Comment