Skip to content

Add rewrite support for errorprone.refasterrules #17487

@Pankraz76

Description

@Pankraz76

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

relates to:

  - org.openrewrite.java.RemoveUnusedImports
  - org.openrewrite.java.format.RemoveTrailingWhitespace
  - org.openrewrite.java.migrate.Java8toJava11
  - org.openrewrite.staticanalysis.LowercasePackage
  - org.openrewrite.staticanalysis.MissingOverrideAnnotation
  - org.openrewrite.staticanalysis.ModifierOrder
  - org.openrewrite.staticanalysis.NoFinalizer
  - org.openrewrite.staticanalysis.RemoveUnusedLocalVariables
  - org.openrewrite.staticanalysis.RemoveUnusedPrivateFields
  - org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods
  - tech.picnic.errorprone.refasterrules.BigDecimalRulesRecipes
  - tech.picnic.errorprone.refasterrules.CharSequenceRulesRecipes
  - tech.picnic.errorprone.refasterrules.ClassRulesRecipes
  - tech.picnic.errorprone.refasterrules.MicrometerRulesRecipes
  - tech.picnic.errorprone.refasterrules.TimeRulesRecipes
  # - org.openrewrite.java.recipes.JavaRecipeBestPractices
  # - org.openrewrite.java.recipes.RecipeNullabilityBestPractices
  # - org.openrewrite.java.recipes.RecipeTestingBestPractices
  # - org.openrewrite.maven.BestPractices
  # - org.openrewrite.staticanalysis.CodeCleanup
  # - org.openrewrite.staticanalysis.CommonStaticAnalysis
  # - org.openrewrite.staticanalysis.EqualsAvoidsNull
  # - org.openrewrite.staticanalysis.JavaApiBestPractices
  # - org.openrewrite.staticanalysis.UnnecessaryThrows
  # - tech.picnic.errorprone.refasterrules.CollectionRulesRecipes
  # - tech.picnic.errorprone.refasterrules.ComparatorRulesRecipes
  # - tech.picnic.errorprone.refasterrules.EqualityRulesRecipes
  # - tech.picnic.errorprone.refasterrules.FileRulesRecipes
  # - tech.picnic.errorprone.refasterrules.NullRulesRecipes
  # - tech.picnic.errorprone.refasterrules.OptionalRulesRecipes
  # - tech.picnic.errorprone.refasterrules.PatternRulesRecipes
  # - tech.picnic.errorprone.refasterrules.PreconditionsRulesRecipes
  # - tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes
  # - tech.picnic.errorprone.refasterrules.StreamRulesRecipes
  # - tech.picnic.errorprone.refasterrules.StringRulesRecipes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions