Skip to content

feat(build): enable five new BugCheckers for errorprone - #148

Open
halibobo1205 wants to merge 6 commits into
developfrom
feat/errorprone-rules-config
Open

feat(build): enable five new BugCheckers for errorprone#148
halibobo1205 wants to merge 6 commits into
developfrom
feat/errorprone-rules-config

Conversation

@halibobo1205

@halibobo1205 halibobo1205 commented Sep 1, 2026

Copy link
Copy Markdown
Owner

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:

Check Kind Production changes required
SelfAssignment built-in Fixes a latent self-assignment in the ReceiveDescriptionCapsule constructor (the field was silently left null; the constructor is currently unreferenced in production code)
ForbidJavaLangMath custom None (repo is already clean). Compile-time guard for the "use StrictMathWrapper, never java.lang.Math" rule; covers calls, static imports, method references, field access, and Math.class
BigDecimalFloatingPointConstructor custom None (repo is already clean). Bans new BigDecimal(double/float) including boxed arguments, constructor references (BigDecimal::new), anonymous subclasses, and named subclasses delegating via super(double)
CatchAndPrintStackTrace built-in Migrates the 5 remaining printStackTrace() call sites to slf4j (TransactionCapsule, FileUtil, JsonRpcApiUtil, JSON-RPC PBFT/Solidity servlets) and removes an unused PedersenHashCapsule method that was the last holdout
ComparatorNeverReturnsZero custom Rewrites the never-return-0 ternary comparators (? 1 : -1) in AssetIssueStore, ExchangeStore, and ProposalStore to contract-safe Comparator.comparingLong chains with explicit tie-breaks

Build wiring: checks run on main source sets only (test compilation is not analyzed), the
generated protocol module and .*/generated/.* paths are excluded, and the Error Prone
toolchain now requires JDK 17+ (clean skip on JDK 8, so x86/JDK 8 builds are unaffected).
gradle/verification-metadata.xml gains entries for the new test-only dependencies (checksums
verified against Maven Central).

Why are these changes required?

  • The old ternary comparators violate the Comparator contract and are
    IllegalArgumentException-prone under TimSort's merge path. The rewrites preserve the
    existing 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 logger
    topics, levels, and JSON-RPC response semantics unchanged.
  • new BigDecimal(double) and java.lang.Math are already forbidden by the project's
    numeric-safety rules; this moves enforcement from regex CI scans and manual review to
    compile time. The regex-based math-check.yml workflow is kept as belt-and-suspenders
    since it also covers test sources and x86/JDK 8 build lanes.

This PR has been tested by:

  • Unit Tests
    • 21 checker tests in :errorprone covering flagged and allowed shapes for all three
      custom checks (static/wildcard imports, method and constructor references, anonymous
      subclasses, instance-qualified calls, @SuppressWarnings, unrelated classes named Math).
    • 8 new framework tests pinning store sort behavior: AssetIssueStoreSortTest,
      ExchangeStoreSortTest, ProposalStoreSortTest, and
      EnergyPriceHistoryEqualExpirationTest (end-to-end: equal-expiration proposals rebuild
      the correct energy price).
    • Existing AssetIssueStoreTest / ExchangeStoreTest / ProposalStoreTest stay green,
      confirming observable ordering is preserved.
  • Manual Testing
    • Repo-wide ./gradlew compileJava on JDK 17 with all five checks at ERROR: zero violations.
    • Every commit builds standalone (git-bisect friendly).
    • JDK 8 build path verified to skip Error Prone cleanly.
    • Cold-cache build verified against the updated dependency-verification metadata.

Follow up

  • math-check.yml can be retired once the compile-time check is considered sufficient on its
    own; it is intentionally retained for now (see above).
  • Additional Error Prone checks can be promoted to ERROR incrementally using the same pattern.

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.
ComparatorNeverReturnsZero blocks reintroducing the old comparator form at compile time.


CodeAnt-AI Description

Enforce deterministic calculations and contract-safe ordering during builds

What Changed

  • Builds now reject direct java.lang.Math usage and floating-point BigDecimal construction to prevent platform-dependent results and rounding errors.
  • Invalid comparators were replaced with ordering that handles equal values safely, including deterministic proposal tie-breaking and correct asset-name ordering.
  • Error handling now records failures through application logs instead of printing stack traces.
  • Added checks and regression tests covering prohibited math and numeric usage, comparator behavior, proposal history reconstruction, and store ordering.

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:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

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:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

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.

@codeant-ai

codeant-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR d517c32 Sep 01, 2026 · 09:28 09:33

@codeant-ai

codeant-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-01T10:31:58.531389Z e4c6897 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codeant-ai codeant-ai Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files label Sep 1, 2026
@codeant-ai

codeant-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown

CodeAnt Nitpicks

1 code suggestion

1. Passing null stores a null protobuf, so later getters or getData() dereference it and throw NullPointerException instead of preserving the capsule invariant.

Null pointer · framework/src/main/java/org/tron/core/capsule/ReceiveDescriptionCapsule.java:18

@halibobo1205
halibobo1205 force-pushed the feat/errorprone-rules-config branch from d517c32 to 49108dc Compare September 1, 2026 09:41
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.
@halibobo1205
halibobo1205 force-pushed the feat/errorprone-rules-config branch from 49108dc to e4c6897 Compare September 1, 2026 09:46
@halibobo1205

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: e4c6897591

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant