Skip to content

Report BadShiftAmount for constant shift amounts - #6324

Open
akasakariko wants to merge 1 commit into
google:masterfrom
akasakariko:bad-shift-amount-constant-variable
Open

akasakariko wants to merge 1 commit into
google:masterfrom
akasakariko:bad-shift-amount-constant-variable

Conversation

@akasakariko

Copy link
Copy Markdown

Fixes #6304

BadShiftAmount only inspected LiteralTree right operands, so a shift by a compile-time constant variable such as private static final int BITS = 32 was not reported even though javac folds it to the same out-of-range amount

Use ASTHelpers.constValue so named constants are covered, and derive the suggested fix from the same constant value instead of casting the right operand to LiteralTree

The TOO_LARGE case in the test also verifies the replacement fix path for named constants

BadShiftAmount only inspected LiteralTree right operands, so a shift by a
compile-time constant variable, such as a private static final int BITS = 32,
was not reported even though javac folds it to the same out-of-range amount

Use ASTHelpers.constValue so named constants are covered, and derive the
suggested fix from the same constant value instead of casting to LiteralTree

This branch has not been deployed

No deployments
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.

BadShiftAmount: a shift by a constant variable that is out of range is not reported

1 participant