Skip to content

Kotlin: normalise kotlin.String to java.lang.String for Java static-method params#7747

Merged
timtebeek merged 2 commits into
mainfrom
tim/resolve-issue-7730
May 20, 2026
Merged

Kotlin: normalise kotlin.String to java.lang.String for Java static-method params#7747
timtebeek merged 2 commits into
mainfrom
tim/resolve-issue-7730

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 20, 2026

Summary

  • Fixes rewrite-kotlin: static-method JavaType keeps kotlin.String for Java String params #7730. 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 an Enhancement-origin FIR wrapper rather than the underlying FirJavaClass, so String parameters leaked through as kotlin.String — silently breaking MethodMatcher patterns written against Java FQNs. The fix falls back to the symbol's owning class when parent isn't itself a FirJavaClass. Java constructors were unaffected (they were already going through methodInvocationType, which uses a different javaOrigin check), so the regression test asserts both shapes resolve to java.lang.String.

Test plan

  • ./gradlew :rewrite-kotlin:test --tests "org.openrewrite.kotlin.tree.JavaStringParameterMappingTest" — new regression test fails on main, passes with the fix
  • ./gradlew :rewrite-kotlin:test — full suite passes, no regressions

…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.
@timtebeek timtebeek requested a review from MBoegers May 20, 2026 11:16
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite May 20, 2026
@timtebeek timtebeek merged commit c764771 into main May 20, 2026
1 check passed
@timtebeek timtebeek deleted the tim/resolve-issue-7730 branch May 20, 2026 11:32
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

rewrite-kotlin: static-method JavaType keeps kotlin.String for Java String params

2 participants