Fix RemoveAnnotation crash on Groovy trees when rewrite-kotlin is on the classpath#7720
Merged
Merged
Conversation
`META-INF/rewrite/mixins/<base-visitor-fqn>` is a shared registry: any
language module can contribute a mixin keyed by the same base visitor
FQN. When more than one language module is on the classpath (e.g.
`rewrite-groovy` + `rewrite-kotlin` together via `rewrite-gradle`),
`discoverRegisteredMixin` would return whichever entry it found first
regardless of the `adaptTo` target. That tripped the assignability
check in `adapt()` with:
IllegalArgumentException: Mixin org.openrewrite.kotlin.RemoveAnnotationKotlinMixin
is not assignable to org.openrewrite.groovy.GroovyVisitor
surfaced through `G.accept` -> `v.adapt(GroovyVisitor.class)` on any
Groovy `build.gradle` parsed by `GradleParser`.
Filter registry entries by `adaptTo.isAssignableFrom(mixinClass)` inside
the lookup itself so that a Kotlin mixin is silently skipped when
adapting to `GroovyVisitor` (and vice versa), while still being applied
when the visit target actually is a Kotlin tree.
3 tasks
timtebeek
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
META-INF/rewrite/mixins/<base-visitor-fqn>.rewrite-kotlinshipsRemoveAnnotationKotlinMixinfororg.openrewrite.java.RemoveAnnotationVisitor.The registry is a shared namespace — multiple language modules can register a mixin for the same base visitor. But
TreeVisitorAdapter.discoverRegisteredMixinreturned the first entry it found without checking it was assignable to the requestedadaptToclass. With bothrewrite-groovyandrewrite-kotlinon the classpath (e.g. viarewrite-gradle,rewrite-spring, etc.), visiting a Groovybuild.gradledid this:G.accept→v.adapt(GroovyVisitor.class)discoverRegisteredMixinreturnedRemoveAnnotationKotlinMixin(registered byrewrite-kotlin)adapt()'s assignability guard threw:This broke every downstream user that runs
RemoveAnnotation(or any Java recipe that ends up adapting throughG) against a Groovy build script — reported viaSpringBootVersionUpgradeTest.upgradeVersionGradlein rewrite-spring.Fix
Filter the registry entries inside
discoverRegisteredMixinbyadaptTo.isAssignableFrom(mixinClass)andcontinuepast mismatched entries. A Kotlin mixin is silently ignored when adapting toGroovyVisitor(and vice versa) while still being picked up when the visit target really is a Kotlin tree.rewrite-core/src/main/java/org/openrewrite/internal/TreeVisitorAdapter.java— skip cross-language mixin entries.rewrite-gradle/src/test/java/org/openrewrite/gradle/RemoveAnnotationGradleTest.java— regression test: runsRemoveAnnotationagainst a Groovybuild.gradle(in a module where bothrewrite-groovyandrewrite-kotlinare on the classpath). Fails onmainwith the exact stack trace above, passes with the fix.Test plan
RemoveAnnotationGradleTest.doesNotApplyKotlinMixinToGroovyTreefails onmainwith the reportedIllegalArgumentException../gradlew :rewrite-core:test :rewrite-kotlin:test :rewrite-groovy:test :rewrite-gradle:test(running locally; no Kotlin@file:OptInremoval coverage exists inrewrite-kotlinitself, so the Kotlin mixin path is only covered indirectly by the existing adapter-level tests).SpringBootVersionUpgradeTest.upgradeVersionGradlein rewrite-spring should pass once this lands.