Kotlin: normalise kotlin.String to java.lang.String for Java static-method params#7747
Merged
Conversation
…ic-method params `KotlinTypeMapping.methodDeclarationType` only remapped Kotlin builtins to their JVM FQNs when the caller-supplied `parent` was a `FirJavaClass`. Static method invocations on Java classes reach this method via `PsiElementAssociations` with `parent` set to the Enhancement-origin FIR wrapper rather than the underlying `FirJavaClass`, so `String` parameters leaked through as `kotlin.String`, breaking `MethodMatcher` patterns written with `String`. Fall back to the symbol's owning class when `parent` isn't itself a `FirJavaClass`. Fixes #7730.
… KotlinTypeMappingTest
MBoegers
approved these changes
May 20, 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
rewrite-kotlin: static-methodJavaTypekeepskotlin.Stringfor JavaStringparams #7730.KotlinTypeMapping.methodDeclarationTypeonly remapped Kotlin builtins to their JVM FQNs when the caller-suppliedparentwas aFirJavaClass. Static method invocations on Java classes reach this method viaPsiElementAssociationswithparentset to an Enhancement-origin FIR wrapper rather than the underlyingFirJavaClass, soStringparameters leaked through askotlin.String— silently breakingMethodMatcherpatterns written against Java FQNs. The fix falls back to the symbol's owning class whenparentisn't itself aFirJavaClass. Java constructors were unaffected (they were already going throughmethodInvocationType, which uses a differentjavaOrigincheck), so the regression test asserts both shapes resolve tojava.lang.String.Test plan
./gradlew :rewrite-kotlin:test --tests "org.openrewrite.kotlin.tree.JavaStringParameterMappingTest"— new regression test fails onmain, passes with the fix./gradlew :rewrite-kotlin:test— full suite passes, no regressions