Skip to content

refactor: drop redundant reference check in Labels.isEmpty() - #2440

Merged
jaydeluca merged 1 commit into
prometheus:mainfrom
david-mollitor-db:simplify-labels-isempty
Sep 7, 2026
Merged

refactor: drop redundant reference check in Labels.isEmpty()#2440
jaydeluca merged 1 commit into
prometheus:mainfrom
david-mollitor-db:simplify-labels-isempty

Conversation

@david-mollitor-db

Copy link
Copy Markdown
Contributor

What

Simplify Labels.isEmpty() by dropping the redundant this == EMPTY reference check.

Why

Labels.equals() already begins with if (this == o) return true;, so this.equals(EMPTY) already returns true for the EMPTY singleton that the this == EMPTY clause guards. Removing the clause is therefore behavior-preserving, and it was the sole reason for the @SuppressWarnings("ReferenceEquality") annotation, which is removed as well.

// before
@SuppressWarnings("ReferenceEquality")
public boolean isEmpty() {
  return this == EMPTY || this.equals(EMPTY);
}

// after
public boolean isEmpty() {
  return this.equals(EMPTY);
}

This also aligns isEmpty() with the rest of Labels, which already uses this.equals(EMPTY) (e.g. in toString()).

This pull request and its description were written by Isaac.

The `this == EMPTY` clause is redundant: Labels.equals() already begins with
`if (this == o) return true;`, so `this.equals(EMPTY)` covers the singleton
case the reference check guards. Removing it is behavior-preserving and also
removes the sole reason for the @SuppressWarnings("ReferenceEquality").

Signed-off-by: David Mollitor <david.mollitor@databricks.com>

@jaydeluca jaydeluca left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks!

@jaydeluca
jaydeluca enabled auto-merge (squash) September 7, 2026 22:22
@jaydeluca
jaydeluca merged commit 39a91dd into prometheus:main Sep 7, 2026
18 checks passed
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