Skip to content

Fix IllegalArgumentException in KotlinParser when dependsOn paths are relative#6882

Merged
jkschneider merged 2 commits intomainfrom
jkschneider/parser-charset
Mar 5, 2026
Merged

Fix IllegalArgumentException in KotlinParser when dependsOn paths are relative#6882
jkschneider merged 2 commits intomainfrom
jkschneider/parser-charset

Conversation

@jkschneider
Copy link
Member

Summary

  • dependsOn inputs created via determinePath have relative paths, but source inputs may have absolute paths
  • When relativeTo is absolute, Path.relativize throws IllegalArgumentException due to the absolute/relative mismatch
  • Resolves dependsOn paths against relativeTo before relativizing, preventing the crash

Test plan

  • Verify existing Kotlin parser tests pass
  • Test with Kotlin sources that have absolute paths and dependsOn with relative paths

…re relative

`dependsOn` inputs created via `determinePath` have relative paths, but source
inputs may have absolute paths. When `relativeTo` is absolute, resolve
dependsOn paths against it so `Path.relativize` in `getRelativePath` doesn't
throw `IllegalArgumentException` due to an absolute/relative mismatch.
…Path

The new test demonstrates the IllegalArgumentException that occurs when
dependsOn provides relative paths but relativeTo is absolute (e.g. a
@tempdir). Also adds the absolute/relative mismatch guard directly in
Parser.Input.getRelativePath, which is called from KotlinTreeParserVisitor.
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Mar 5, 2026
@jkschneider jkschneider merged commit 2301028 into main Mar 5, 2026
1 check passed
@jkschneider jkschneider deleted the jkschneider/parser-charset branch March 5, 2026 16:08
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Mar 5, 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.

3 participants