feat(build): enable five new BugCheckers for errorprone - #148
feat(build): enable five new BugCheckers for errorprone#148halibobo1205 wants to merge 6 commits into
Conversation
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
CodeAnt Nitpicks1 code suggestion1. Passing
|
d517c32 to
49108dc
Compare
Add a custom ErrorProne BugChecker (ForbidJavaLangMath) as a compile-time guard against java.lang.Math usage. The regex-based math-check.yml workflow is kept as belt-and-suspenders: it also covers test sources and x86/JDK8 build lanes, which Error Prone (main sources of non-protocol modules, JDK 17+ builds only) does not see.
forbid floating-point BigDecimal constructors
Error Prone 2.42.0 ships Java 17 class files, skip the custom checker below JDK 17.
49108dc to
e4c6897
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
User description
What does this PR do?
Extends the Error Prone setup introduced in tronprotocol#6698 with five more checks, enforced at ERROR
severity on production sources, plus the mechanical fixes they require:
SelfAssignmentReceiveDescriptionCapsuleconstructor (the field was silently leftnull; the constructor is currently unreferenced in production code)ForbidJavaLangMathStrictMathWrapper, neverjava.lang.Math" rule; covers calls, static imports, method references, field access, andMath.classBigDecimalFloatingPointConstructornew BigDecimal(double/float)including boxed arguments, constructor references (BigDecimal::new), anonymous subclasses, and named subclasses delegating viasuper(double)CatchAndPrintStackTraceprintStackTrace()call sites to slf4j (TransactionCapsule,FileUtil,JsonRpcApiUtil, JSON-RPC PBFT/Solidity servlets) and removes an unusedPedersenHashCapsulemethod that was the last holdoutComparatorNeverReturnsZero? 1 : -1) inAssetIssueStore,ExchangeStore, andProposalStoreto contract-safeComparator.comparingLongchains with explicit tie-breaksBuild wiring: checks run on main source sets only (test compilation is not analyzed), the
generated
protocolmodule and.*/generated/.*paths are excluded, and the Error Pronetoolchain now requires JDK 17+ (clean skip on JDK 8, so x86/JDK 8 builds are unaffected).
gradle/verification-metadata.xmlgains entries for the new test-only dependencies (checksumsverified against Maven Central).
Why are these changes required?
Comparatorcontract and areIllegalArgumentException-prone under TimSort's merge path. The rewrites preserve theexisting order on all deterministic paths; ties (equal sort keys) are now deterministic
instead of iteration-order dependent. These sorted outputs feed API responses only — no
consensus path consumes them.
printStackTrace()bypasses the logging configuration entirely. The migration keeps loggertopics, levels, and JSON-RPC response semantics unchanged.
new BigDecimal(double)andjava.lang.Mathare already forbidden by the project'snumeric-safety rules; this moves enforcement from regex CI scans and manual review to
compile time. The regex-based
math-check.ymlworkflow is kept as belt-and-suspenderssince it also covers test sources and x86/JDK 8 build lanes.
This PR has been tested by:
:errorpronecovering flagged and allowed shapes for all threecustom checks (static/wildcard imports, method and constructor references, anonymous
subclasses, instance-qualified calls,
@SuppressWarnings, unrelated classes namedMath).AssetIssueStoreSortTest,ExchangeStoreSortTest,ProposalStoreSortTest, andEnergyPriceHistoryEqualExpirationTest(end-to-end: equal-expiration proposals rebuildthe correct energy price).
AssetIssueStoreTest/ExchangeStoreTest/ProposalStoreTeststay green,confirming observable ordering is preserved.
./gradlew compileJavaon JDK 17 with all five checks at ERROR: zero violations.Follow up
math-check.ymlcan be retired once the compile-time check is considered sufficient on itsown; it is intentionally retained for now (see above).
Extra details
Ordering-behavior note for reviewers: for equal sort keys the previous comparators produced an
iteration-order-dependent result; the new explicit tie-breaks make it deterministic. The only
intentional ordering change is the equal-name tie-break in paginated asset-issue listings.
ComparatorNeverReturnsZeroblocks reintroducing the old comparator form at compile time.CodeAnt-AI Description
Enforce deterministic calculations and contract-safe ordering during builds
What Changed
java.lang.Mathusage and floating-pointBigDecimalconstruction to prevent platform-dependent results and rounding errors.Impact
✅ Deterministic calculations across platforms✅ Fewer sorting failures on equal values✅ Correct proposal and asset ordering💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.