Is there a way to exclude Java equals(), hashCode() methods from code duplication?

In short lived branches where lines changed are small, we can easily get a high percentage of code duplication if we add a Java equals(), hashCode() or toString() method. We fail our build, if SonarCloud fails, so developers are stuck. There are several ways around this:

  1. Increase code duplication percentage, but this allows for greater code duplication.
  2. Manually resolve as false positive, but that just trains developers to come bother me whenever they have a problem :slight_smile: Plus, we have developers in different time zones, so they are stuck until I wake up.
  3. Ignore Java equals(), hashCode() and toString() methods. Is this possible?


Hi Fred,

this is unfortunately not possible to ignore methods only.
Maybe you can suggest your team to use the Apache Commons Lang API (HashCodeBuilder, EqualsBuilder, …etc) to get rid of these duplications?