Skip to content

feat(errorprone): enforce no-java.lang.Math rule at compile time#130

Open
halibobo1205 wants to merge 1 commit into
release_v4.8.2from
feat/forbid-java-lang-math-errorprone
Open

feat(errorprone): enforce no-java.lang.Math rule at compile time#130
halibobo1205 wants to merge 1 commit into
release_v4.8.2from
feat/forbid-java-lang-math-errorprone

Conversation

@halibobo1205

@halibobo1205 halibobo1205 commented May 29, 2026

Copy link
Copy Markdown
Owner

User description

Replace the regex-based .github/workflows/math-check.yml scan with a custom ErrorProne BugChecker (ForbidJavaLangMath) in the :errorprone module. It resolves symbols on the type-attributed AST, so it catches every usage form (direct, fully-qualified, statically-imported, method references, field access) with no string/comment false positives. java.lang.StrictMath remains allowed.

  • add ForbidJavaLangMath BugChecker (auto-registered via @AutoService)
  • enable -Xep:ForbidJavaLangMath:ERROR in build.gradle
  • exempt the canonical x86 MathWrapper via @SuppressWarnings
  • delete .github/workflows/math-check.yml

Note: ErrorProne runs only on JDK 11+, so the rule is no longer enforced on the JDK 8 (x86_64) build path.


CodeAnt-AI Description

Block direct java.lang.Math usage during Java builds

What Changed

  • Builds now fail when code uses java.lang.Math, including direct calls, fully qualified calls, static imports, method references, field access, and Math.class
  • The old file-scanning workflow was removed, so the rule is checked during compilation instead of by a separate script
  • java.lang.StrictMath stays allowed, and the standard x86 math wrapper is exempted so existing platform-specific code still builds

Impact

✅ Earlier rejection of forbidden Math usage
✅ Fewer false alarms from comments and strings
✅ Less chance of non-deterministic math slipping into consensus code

💡 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 May 29, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.


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

@halibobo1205

Copy link
Copy Markdown
Owner Author

@codex: review

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label May 29, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d66743805

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

Comment thread .github/workflows/math-check.yml
Comment thread errorprone/src/main/java/errorprone/ForbidJavaLangMath.java
Comment thread errorprone/src/main/java/errorprone/ForbidJavaLangMath.java
@codeant-ai

codeant-ai Bot commented May 29, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

@halibobo1205

Copy link
Copy Markdown
Owner Author

@codex: review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@halibobo1205

Copy link
Copy Markdown
Owner Author

@CodeAnt-AI: review

@codeant-ai

codeant-ai Bot commented Jun 1, 2026

Copy link
Copy Markdown

CodeAnt AI is running the review.


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

@codeant-ai codeant-ai Bot added size:L This PR changes 100-499 lines, ignoring generated files and removed size:L This PR changes 100-499 lines, ignoring generated files labels Jun 1, 2026
@codeant-ai

codeant-ai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Sequence Diagram

This PR replaces the GitHub Actions regex scanner with an ErrorProne BugChecker that blocks direct java.lang.Math usage during compilation, while allowing explicitly suppressed wrapper code. The diagram shows how the checker participates in the build to either fail or pass compilation based on detected Math usage.

sequenceDiagram
    participant Developer
    participant Build as Build tool
    participant JavaCompiler
    participant Checker as ForbidJavaLangMath
    participant Source as Java source file

    Developer->>Build: Run Java build
    Build->>JavaCompiler: Compile sources with ErrorProne enabled
    JavaCompiler->>Checker: Invoke ForbidJavaLangMath on each source AST
    Checker->>Source: Inspect symbols for java.lang.Math usage

    alt Forbidden Math usage without suppression
        Checker-->>JavaCompiler: Report ForbidJavaLangMath error
        JavaCompiler-->>Developer: Build fails with error
    else Only allowed or suppressed usages
        Checker-->>JavaCompiler: No violations
        JavaCompiler-->>Developer: Build succeeds
    end
Loading

Generated by CodeAnt AI

@codeant-ai

codeant-ai Bot commented Jun 1, 2026

Copy link
Copy Markdown

CodeAnt AI finished running the review.


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

Replace the regex-based .github/workflows/math-check.yml scan with a
custom ErrorProne BugChecker (ForbidJavaLangMath) in the :errorprone
module. It resolves symbols on the type-attributed AST, so it catches
every usage form (direct, fully-qualified, statically-imported,
method references, field access) with no string/comment false
positives. java.lang.StrictMath remains allowed.

- add ForbidJavaLangMath BugChecker (auto-registered via @autoservice)
- enable -Xep:ForbidJavaLangMath:ERROR in build.gradle
- exempt the canonical x86 MathWrapper via @SuppressWarnings
- delete .github/workflows/math-check.yml
@halibobo1205 halibobo1205 force-pushed the feat/forbid-java-lang-math-errorprone branch from 385f6e4 to ba79d50 Compare June 8, 2026 06:23
@codeant-ai

codeant-ai Bot commented Jun 8, 2026

Copy link
Copy Markdown

CodeAnt AI is running Incremental review


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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@codeant-ai codeant-ai Bot added size:L This PR changes 100-499 lines, ignoring generated files and removed size:L This PR changes 100-499 lines, ignoring generated files labels Jun 8, 2026
@codeant-ai

codeant-ai Bot commented Jun 8, 2026

Copy link
Copy Markdown

CodeAnt AI Incremental review completed.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant