8000 Add `rewrite` support for `errorprone.refasterrules` · Issue #41761 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Add rewrite support for errorprone.refasterrules #41761

Closed as not planned
Closed as not planned

Description

@Pankraz76

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:

Proposal

  1. Add support for errorprone.refasterrules-based rewrites
  2. Implement with opt-in adoption (no breaking changes)
  3. 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

Thanks for considering.

Discussion

No response

Motivation

No response

Details

No response

Activity

  1. added
    kind/enhancement
    on Aug 8, 2025
  2. ahus1 commented on Aug 14, 2025

    @ahus1
    < 8000 div class="narrowViewportWrapper__C5cNkS CommentHeaderContentContainer__qvr9Sa" data-testid="comment-header-left-side-items">
    Member

    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:

    • What would a developer do differently with the changes?
    • What would the CI do differently with the changes, and how would its observed behavior change?
  • Pankraz76 commented on Aug 14, 2025

    @Pankraz76
    Author

    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 dryRun on CI checking for consistency. Suggesting the simple run goal fixing the issues right away.

    The whole situation can be seen on jenkins, as it behaves like spotless.

  • Pankraz76 commented on Aug 14, 2025

    @Pankraz76
    Author

    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:

    [INFO] Project [Jenkins coverage] Parsing source files
    [INFO] Running recipe(s)...
    [INFO] Printing available datatables to: target/rewrite/datatables/2025-08-14_14-50-26-834
    [WARNING] The recipe produced 116 warning(s). Please report this to the recipe author.
    [WARNING]     /Users/vincent.potucek/IdeaProjects/jenkins/target/rewrite/rewrite.patch
    [WARNING] Estimate time saved: 5h 10m
    [WARNING] Run 'mvn rewrite:run' to apply the recipes.
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary for Jenkins main module 2.524-SNAPSHOT:
    [INFO] 
    [INFO] Jenkins main module ................................ SUCCESS [  9.236 s]
    [INFO] Jenkins BOM ........................................ SUCCESS [  0.038 s]
    [INFO] Internal SPI for WebSocket ......................... SUCCESS [  0.113 s]
    [INFO] Jetty 12 (EE 9) implementation for WebSocket ....... SUCCESS [  0.055 s]
    [INFO] Jenkins cli ........................................ SUCCESS [  0.362 s]
    [INFO] Jenkins core ....................................... SUCCESS [  2.294 s]
    [INFO] Jenkins war ........................................ SUCCESS [  1.793 s]
    [INFO] Tests for Jenkins core ............................. SUCCESS [  1.186 s]
    [INFO] Jenkins coverage ................................... FAILURE [ 31.668 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  47.231 s
    [INFO] Finished at: 2025-08-14T14:50:26+02:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:6.15.0:dryRun (default-cli) on project jenkins-coverage: Applying recipes would make changes. See logs for more details. -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
    [ERROR] 
    [ERROR] After correcting the problems, you can resume the build with the command
    [ERROR]   mvn <args> -rf :jenkins-coverage
    ➜  jenkins git:(rw) ✗ 
    
  • ahus1 commented on Aug 14, 2025

    @ahus1
    Member

    @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 commented on Aug 14, 2025

    @Pankraz76
    Author

    Yes rewrite is capable of doing so but this is spamming the PR as can be seen on rewrite itself.

    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:

    Image
  • Pankraz76 commented on Aug 15, 2025

    @Pankraz76
    Author

    elastic has implemented your assumption, of patching the changes on CI, regarding spotless already:

  • deleted a comment from Pankraz76 on Aug 25, 2025
  • Pankraz76 commented on Aug 26, 2025

    @Pankraz76
    Author

    Please excuse my emotional breakout.

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

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      kind/enhancement

      Type

      No type

      Fields

      No fields configured for issues without a type.

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        0