Skip to content

Commit

Permalink
doc: Update docs/HANDLED_RULES.md (#925)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and github-actions[bot] authored Oct 23, 2022
1 parent 88b580a commit d6743d0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/HANDLED_RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,15 @@ Example:
#### Strings and Boxed types should be compared using "equals()" ([Sonar Rule 4973](https://rules.sonarsource.com/java/RSPEC-4973))

Any comparison of strings or boxed types using `==` or `!=` is replaced by `equals`.
By default, we use `equals` on the left operand, so we add a null check before comparison.

Example:
```diff
- if (firstName == lastName) // Noncompliant
+ if (firstName.equals(lastName))
+ if (firstName != null && firstName.equals(lastName))
...
- return b != a; // Noncompliant
+ return !b.equals(a);
+ return b != null && !b.equals(a);
```

Check out an accepted PR in [Apache Sling Discovery](https://github.com/apache/sling-org-apache-sling-discovery-impl/pull/1) that repairs one CompareStringsBoxedTypesWithEquals violation.
Expand Down

0 comments on commit d6743d0

Please sign in to comment.