Skip to content

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented Jun 17, 2025

The non-equality comparisons (<, <=, >, >=) require numeric promotion always, but equality comparisons (==, !=) only require it if at least one argument is numeric type (that is, primitive but not boolean). If both arguments are not numeric types, no numeric promotion should happen.

We previously guarded against that in a naive way: the numericPromotion() method returned early when both operands were of the same type after unboxing. This leads to incorrect conversion in case of equality comparisons on primitive wrapper types (and may lead to NPE at runtime). This commit adds proper guard to the appropriate place.

Note that there are other occurences of numericPromotion() which are not guarded by numericPromotionRequired(). These are in BinOp and in Cmp, where on both places the operation is always numeric and so always requires numeric promotion.

The non-equality comparisons (`<`, `<=`, `>`, `>=`) require numeric promotion
always, but equality comparisons (`==`, `!=`) only require it if at least one
argument is numeric type (that is, primitive but not `boolean`). If both
arguments are not numeric types, no numeric promotion should happen.

We previously guarded against that in a naive way: the `numericPromotion()`
method returned early when both operands were of the same type after unboxing.
This leads to incorrect conversion in case of equality comparisons on primitive
wrapper types (and may lead to NPE at runtime). This commit adds proper guard
to the appropriate place.

Note that there are other occurences of `numericPromotion()` which are not
guarded by `numericPromotionRequired()`. These are in `BinOp` and in `Cmp`,
where on both places the operation is always numeric and so always requires
numeric promotion.
@dmlloyd dmlloyd merged commit e8338ac into quarkusio:main Jun 17, 2025
1 check passed
@Ladicek Ladicek deleted the fix-numeric-promotion-for-eq-ne branch June 17, 2025 12:33
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