Repository navigation
Closed as not planned
Labels
kind/enhancementCategorizes a PR related to an enhancement
Description
Description
Add rewrite support for errorprone.refasterrules
I’d like to propose integrating Google’s Error Prone and its Picnic extension (demonstrated in Automating Away Bugs with Error Prone | PlatformCon 2023) to enable automated bug fixes via rewrite rules. This would complement Checkstyle’s static analysis capabilities by addressing semantic bugs rather than stylistic issues.
Motivation
Error Prone’s refaster/rewrite rules can automatically:
- Fix common bug patterns (e.g.,
String.equals()misuse) - Modernize code (e.g., JDK migration helpers)
- Enforce best practices (e.g., null-check improvements)
Real-world adoptions show tangible benefits:
- Issue #17487: Introduce
Rewritecovering S1144: Unused "private" methods should be removed checkstyle/checkstyle#17545 - Fix #5953: [java] PoC: Add
rewritesupport forerrorprone.refasterrulespmd/pmd#5956 - Introduce
Rewrite & PMDcovering S1144: Unused "private" methods should be removed opensearch-project/OpenSearch#18791 - PoC: Add
rewritesupport forerrorprone.refasterrulesdiffplug/spotless#2576 - PoC: Add
rewritesupport forerrorprone.refasterrulesapache/kafka#20219
Proposal
- Add support for
errorprone.refasterrules-based rewrites - Implement with opt-in adoption (no breaking changes)
- Include suppression mechanisms for API constraints
Discussion Points
Need consensus on:
- Scope of auto-fixes
- Preferred suppression strategy
- Integration approach
Next Steps
I’m happy to:
- Prepare a PoC demonstrating the value
- Collaborate on implementation strategy
- Address any concerns about compatibility
Discussion
No response
Motivation
more time on development then fixing or discussing bugs or conventions
Details
- [GR-68578] Add
rewritesupport forerrorprone.refasterrulesoracle/graal#11898 - OPE-930: Add
rewritesupport forerrorprone.refasterrulesSonarSource/sonarqube#3389
Thanks for considering.
Discussion
No response
Motivation
No response
Details
No response
Metadata
Metadata
Assignees
Labels
kind/enhancementCategorizes a PR related to an enhancement
Type
Fields
No fields configured for issues without a type.
Activity
ahus1 commentedon Aug 14, 2025
Thank you for creating this issue. I understand this can improve the code, still I would like to understand how this changes the workflows / when and who commits any code changes.
Namely:
Pankraz76 commentedon Aug 14, 2025
Its a simple quality gate, that fails (on CI) when the code is in dirty/corrupt state, whatever this is is up to you and very generic. It can be everything from whitespaces to real (security) bugs.
There are many ways to integrate this.
The simples one is to run
dryRunon CI checking for consistency. Suggesting the simplerungoal fixing the issues right away.The whole situation can be seen on jenkins, as it behaves like spotless.
checkgoal ofmaven-spotless-pluginjenkinsci/jenkins#10968Pankraz76 commentedon Aug 14, 2025
like to reading this console output, every dev should know how to help themself.
of course this could be automated even further considering maven parent:
ahus1 commentedon Aug 14, 2025
@Pankraz76 - reading your last comment, it doesn't provide me straight answers to my questions. I try to write down my assumptions below, and then please confirm if they are correct.
Question: What would a developer do differently with the changes?
Assumption: The developers would still run the same commands, but they would fail with a Maven error when the code changes wouldn't comply with the rules. There is no descriptive error message, but a patch file is provided.
Question: What would the CI do differently with the changes, and how would its observed behavior change?
Assumption: CI would still run the same commands, but they would fail with a Maven error when the code changes wouldn't comply with the rules. There is no descriptive error message, but a patch file is provided which is sitting on the server which would then need to be shown on the console / provided as a build artifact.
Pankraz76 commentedon Aug 14, 2025
Yes rewrite is capable of doing so but this is spamming the PR as can be seen on rewrite itself.
UseForEachLoopopenrewrite/rewrite-static-analysis#663 (comment)I would suggest to start simple as all the other projects like maven spring quarkus doing it, like suggested by me PR.
Impose some quality gate and demand compliance. It will tell how to fix like in the output mentioned. This could then be included like with spotless on jenkins. As its just the same. Rewrite can cover spotless but not the other way around. Rewrite is capable of migrating the whole app to new java version.
As its kind of law and order to run verify goal locally before push it should be quite self explaining how to pass the build.
[WARNING] Run 'mvn rewrite:run' to apply the recipes.This solution is approach in checkstyle as well:
Issue #17487: Introduce
Rewritecovering S1144: Unused "private" methods should be removed checkstyle/checkstyle#17545https://docs.openrewrite.org/running-recipes/popular-recipe-guides/migrate-to-java-17
fix missing plugin mentioning of spotbugs and spotless in CONTRIBUTING.md jenkinsci/jenkins#10971
Pankraz76 commentedon Aug 15, 2025
elastic has implemented your assumption, of patching the changes on CI, regarding spotless already:
rewritesupport forRemoveUnusedImportselastic/elasticsearch#131611Pankraz76 commentedon Aug 26, 2025
Please excuse my emotional breakout.