This is not a bug report or false positive finding per se, but I’m wondering whether the rule S1142 should apply to methods which are usually auto generated. The only example I currently have is the equals()
method:
public class OverridenEquals {
private String stringMember;
private int intMember;
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
OverridenEquals other = (OverridenEquals) obj;
return intMember == other.intMember && Objects.equals(stringMember, other.stringMember);
}
...
}
This is what eclipse generates when using Objects.equals(Object, Object)
, using Object.equals(Object)
there are many more cases and early returns.
So what do you think about this case? Would you handle the method the same as any other method? How would you refactor the method? Would you close any issue as ‘won’t fix’? Would you advise to use Lombok?
Thanks for the input!