Skip to content
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

StatusOr.equals() cannot compare Status instances #11949

Open
panchenko opened this issue Mar 7, 2025 · 1 comment
Open

StatusOr.equals() cannot compare Status instances #11949

panchenko opened this issue Mar 7, 2025 · 1 comment
Milestone

Comments

@panchenko
Copy link
Contributor

StatusOr has been introduced in #11330
The implemented equals() method tries to compare value or status.
However, Status.equals() intentionally does not compare its fields.

* Equality on Statuses is not well defined. Instead, do comparison based on their Code with
* {@link #getCode}. The description and cause of the Status are unlikely to be stable, and
* additional fields may be added to Status in the future.
*/
@Override
public boolean equals(Object obj) {
return super.equals(obj);

The corresponding StatusOr test compares same Status instance and passes

public void equals_sameStatuses() {
assertThat(StatusOr.fromStatus(Status.ABORTED)).isEqualTo(StatusOr.fromStatus(Status.ABORTED));

but would fail if there is a description

String msg = "1";
assertThat(StatusOr.fromStatus(Status.ABORTED.withDescription(msg)))
    .isEqualTo(StatusOr.fromStatus(Status.ABORTED.withDescription(msg)));
@ejona86
Copy link
Member

ejona86 commented Mar 27, 2025

@kannanjgithub, what were you thinking the change here would be? Given the following would fail without using StatusOr, I don't really know what the expectation would be:

assertThat(Status.ABORTED.withDescription(msg))
    .isEqualTo(Status.ABORTED.withDescription(msg));

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

No branches or pull requests

3 participants