Skip to content

ARTEMIS-5442 use Objects.equals consistently#5780

Merged
tabish121 merged 1 commit intoapache:mainfrom
jbertram:ARTEMIS-5442
Jun 23, 2025
Merged

ARTEMIS-5442 use Objects.equals consistently#5780
tabish121 merged 1 commit intoapache:mainfrom
jbertram:ARTEMIS-5442

Conversation

@jbertram
Copy link
Copy Markdown
Contributor

This commit enforces consistency for Object#equals implementations across the code-base via the following changes:

  • Use Objects#equals whenever possible.
  • Use instanceof rather than explicit null checks & getClass.
  • Use "obj" for parameter name and "other" for cast object name.
  • Always check identity using == first.
  • Use explicit curly brackets for conditionals to increase clarity.

@Override
public int hashCode() {
return rawValue.hashCode();
return Objects.hash(rawValue);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Objects.hash() creates an array on each call, is that desirable here vs Objects.hashCode()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@Override
public boolean equals(Object obj) {
if (this == obj) {
if (this ==
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting change seems wrong here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return false;
}
return true;
return correlationID == other.correlationID && true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can drop the && true here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@Override
public boolean equals(Object obj) {
if (this == obj) {
if (this ==
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd formatting adjustment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@Override
public boolean equals(Object obj) {
if (this == obj) {
if (this ==
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

public boolean equals(final Object o) {
if (this == o) {
public boolean equals(final Object obj) {
if (this ==
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

public boolean equals(final Object o) {
if (this == o) {
public boolean equals(final Object obj) {
if (this ==
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

public boolean equals(final Object o) {
if (this == o) {
public boolean equals(final Object obj) {
if (this ==
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@Override
public boolean equals(final Object o) {
if (this == o) {
public boolean equals(final Object obj) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

public boolean equals(Object o) {
if (this == o)
public boolean equals(Object obj) {
if (this ==
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

odd formatting ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

This commit enforces consistency for `Object#equals` implementations
across the code-base via the following changes:

 - Use `Objects#equals` whenever possible.
 - Use `instanceof` rather than explicit null checks & `getClass`.
 - Use "obj" for parameter name and "other" for cast object name.
 - Always check identity using `==` first.
 - Use explicit curly brackets for conditionals to increase clarity.
@tabish121 tabish121 merged commit 4890bb3 into apache:main Jun 23, 2025
6 checks passed
@jbertram
Copy link
Copy Markdown
Contributor Author

The commit message should have referenced ARTEMIS-5542. 🤦‍♂️

@jbertram jbertram deleted the ARTEMIS-5442 branch July 2, 2025 21:36
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