[FLINK-33725][core] Return false from MathUtils.isPowerOf2 for non-positive values#28557
[FLINK-33725][core] Return false from MathUtils.isPowerOf2 for non-positive values#28557vasiliy-mikhailov wants to merge 1 commit into
Conversation
spuru9
left a comment
There was a problem hiding this comment.
Changes look good, Can you update the PR description as per guidlines.
|
Thanks for taking a look. I've updated the description to follow the PR template (filled in the full "potentially affect" checklist and the verifying section). |
Can you add the AI declaration too? |
|
Added an AI assistance disclosure to the description. For transparency: an AI pipeline was used to scan a large amount of code, surface suspected bugs, reproduce a subset with failing unit tests and generate fixes, and prepare PRs; each one — including this — was reviewed and verified by a human (fail-before / pass-after test run plus code review) before opening. |
|
Can you refer #28463 (comment) |
What is the purpose of the change
MathUtils.isPowerOf2(long)returnstruefor0and forLong.MIN_VALUE,neither of which is a power of two.
0 & (0 - 1) == 0andLong.MIN_VALUE & (Long.MIN_VALUE - 1) == 0, so the existing bit trick alonemisclassifies non-positive inputs. This fixes
FLINK-33725.
Brief change log
isPowerOf2withvalue > 0so non-positive values returnfalse.MathUtilTest#testPowerOfTwowith the0,-1andLong.MIN_VALUEcases.Verifying this change
Added assertions to
MathUtilTest#testPowerOfTwofor0,-1andLong.MIN_VALUE. Running just that test on the currentmaster(before the one-line change) fails, and passes after it:Before the fix (on
master):After the fix:
Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Claude Opus 4.8)