Skip to content

Flag non-relational operations and unary negation on compareTo results in CompareToZero. - #6063

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_955519932
Aug 24, 2026
Merged

Flag non-relational operations and unary negation on compareTo results in CompareToZero.#6063
copybara-service[bot] merged 1 commit into
masterfrom
test_955519932

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Flag non-relational operations and unary negation on compareTo results in CompareToZero.

The CompareToZero bug pattern previously only flagged addition, subtraction, and specific comparisons on compareTo results. This change updates the check to flag all non-relational binary operations (including arithmetic, string concatenation, and bitwise operations) as well as unary negation (-x.compareTo(y)).

Specific diagnostic messages are added for arithmetic operations (clarifying {-1, 0, +1} range assumptions and overflow risks), unary negation, and general non-relational operations, recommending Integer.signum.

The check is temporarily disabled via Error Prone flags until depot violations are cleaned up.

…s in `CompareToZero`.

The `CompareToZero` bug pattern previously only flagged addition, subtraction, and specific comparisons on `compareTo` results. This change updates the check to flag all non-relational binary operations (including arithmetic, string concatenation, and bitwise operations) as well as unary negation (`-x.compareTo(y)`).

Specific diagnostic messages are added for arithmetic operations (clarifying `{-1, 0, +1}` range assumptions and overflow risks), unary negation, and general non-relational operations, recommending `Integer.signum`.

The check is temporarily disabled via Error Prone flags until depot violations are cleaned up.

PiperOrigin-RevId: 970134346
@copybara-service
copybara-service Bot merged commit 3cf3c69 into master Aug 24, 2026
2 checks passed
@copybara-service
copybara-service Bot deleted the test_955519932 branch August 24, 2026 22:58
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.

1 participant