Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-1553

FP on S2162: final equals methods using instanceof their owner are symmetric

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.12
    • Component/s: Rules
    • Labels:
      None

      Description

      final equals methods can rely on instanceof when comparing with their owner. Indeed, as the subclasses won't be able to override the method, the symmetry contract is preserved.

      public class BaseClass {
      
        @Override
        public final boolean equals(Object obj) {
            if (this == obj) return true;
            if (obj == null) return false;
            if (!(obj instanceof BaseClass)) return false; // Compliant, as 'equals' is final
            // ...
        }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                michael.gumowski Michael Gumowski
                Reporter:
                michael.gumowski Michael Gumowski
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: