Skip to content

StatusOr.equals() cannot compare Status instances #11949

Closed
@panchenko

Description

@panchenko

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)));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions