Skip to content

Enable & fix inspection: equals() called on enum value #2819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2021

Conversation

Bennett-Lynch
Copy link
Contributor

Reports equals() calls on enum constants.

Such calls can be replaced by an identity comparison (==) because two
enum constants are equal only when they have the same identity.

A quick-fix is available to change the call to a comparison.

Example:

boolean foo(MyEnum value) {
  return value.equals(MyEnum.FOO);
}

After the quick-fix is applied:

boolean foo(MyEnum value) {
  return value == MyEnum.FOO;
}

License

  • I confirm that this pull request can be released under the Apache 2 license

Reports `equals()` calls on enum constants.

Such calls can be replaced by an identity comparison (`==`) because two
enum constants are equal only when they have the same identity.

A quick-fix is available to change the call to a comparison.

Example:

```
boolean foo(MyEnum value) {
  return value.equals(MyEnum.FOO);
}
```

After the quick-fix is applied:

```
boolean foo(MyEnum value) {
  return value == MyEnum.FOO;
}
```
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 3, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

84.9% 84.9% Coverage
0.0% 0.0% Duplication

@Bennett-Lynch Bennett-Lynch merged commit f7705c4 into aws:master Nov 3, 2021
aws-sdk-java-automation pushed a commit that referenced this pull request Nov 28, 2023
…d90c1dfcf

Pull request: release <- staging/d918cad1-d118-454f-b024-acdd90c1dfcf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants