Skip to content

Recognize compile-time TimeUnit conversion constants - #6286

Open
wozhenbang2004 wants to merge 2 commits into
google:masterfrom
wozhenbang2004:fix/time-unit-constant-6279
Open

wozhenbang2004 wants to merge 2 commits into
google:masterfrom
wozhenbang2004:fix/time-unit-constant-6279

Conversation

@wozhenbang2004

Copy link
Copy Markdown

Fixes #6279.

Use javac's compile-time constant value rather than parsing the source text, so integral expressions, named constants, and literals with separators or radix prefixes follow the existing conversion checks. This also avoids an incorrect suggested result for octal literals.

Only treat a receiver as a known unit when its symbol is a TimeUnit enum constant. For an enum constant accessed through an expression, report the conversion without replacing the whole call, preserving the receiver's evaluation and possible side effects. The tests cover constant and nonconstant arguments, suggested fixes, shadowing variables, and expression-qualified receivers.

Validation:

  • git diff --check passed.
  • Independent javac 21 attribution probes covered 15 constant/nonconstant expressions and six receiver-identity cases. These probes do not run the Error Prone checker.
  • The targeted Maven checker tests were attempted but did not run: the upstream build requires a JDK 25 toolchain, while this environment has JDK 21. CI results are pending.

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.

TimeUnitConversionChecker: constant argument only recognised if its source text parses as a long

1 participant