Skip to content

Skip RenameUnderscoreIdentifier on Kotlin and Groovy sources#1114

Merged
timtebeek merged 1 commit into
mainfrom
MBoegers/customer-request-2449
May 28, 2026
Merged

Skip RenameUnderscoreIdentifier on Kotlin and Groovy sources#1114
timtebeek merged 1 commit into
mainfrom
MBoegers/customer-request-2449

Conversation

@MBoegers
Copy link
Copy Markdown
Contributor

@MBoegers MBoegers commented May 28, 2026

Summary

  • RenameUnderscoreIdentifier's only precondition was UsesJavaVersion<>(1, 8). In polyglot projects whose Kotlin sources target Java 8 bytecode, the recipe visited Kotlin lambdas and rewrote legal _ placeholder parameters to __, which is reserved in Kotlin 2.0+ (e.g. { _, _ -> ... } became { __, __ -> ... }, producing two compile errors per site).

  • Add Preconditions.not(new KotlinFileChecker<>()) and Preconditions.not(new GroovyFileChecker<>()) to the precondition, mirroring the gate already present on the sibling ReplaceUnusedVariablesWithUnderscore recipe.

  • Add a regression test (kotlinFileNotChanged) asserting a Java-8-marked Kotlin source containing { _, _ -> ... } is left untouched.

  • Resolves moderneinc/customer-requests#2449.

Test plan

  • ./gradlew test --tests 'org.openrewrite.java.migrate.lang.RenameUnderscoreIdentifierTest' passes, including the new Kotlin regression.
  • Existing Java-only tests continue to pass (the new preconditions do not affect plain Java sources).

Mirror the precondition gate already used by the sibling
`ReplaceUnusedVariablesWithUnderscore` so the recipe no longer rewrites
legal `_` placeholders in Kotlin lambdas to `__`, which is reserved in
Kotlin 2.0+.
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite May 28, 2026
@timtebeek timtebeek merged commit dec86d0 into main May 28, 2026
1 check passed
@timtebeek timtebeek deleted the MBoegers/customer-request-2449 branch May 28, 2026 16:36
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants