Skip to content

fix(kotlin-lsp): use Android-compatible Path creation - #2324

Open
Wadamzmail wants to merge 1 commit into
appdevforall:stagefrom
Wadamzmail:community/fix-uncompitable-kotlin-lsp-api-with-android10
Open

Wadamzmail wants to merge 1 commit into
appdevforall:stagefrom
Wadamzmail:community/fix-uncompitable-kotlin-lsp-api-with-android10

Conversation

@Wadamzmail

@Wadamzmail Wadamzmail commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2322 (#2322)

Summary

The Kotlin language server fails to initialize on devices whose runtime does not provide the Java 11 static factory java.nio.file.Path.of(...). This PR replaces every Path.of(...) call in the Kotlin LSP compiler module with Paths.get(...), which is available on all Android versions.

Problem

When the Kotlin project is updated, CompilerSession crashes while building the compilation environment. The full stack trace is also attached in #2322:

ERROR [DefaultDispatcher-worker-8] CompilerSession: Kotlin project update failed
java.lang.NoSuchMethodError: No static method of(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
  in class Ljava/nio/file/Path; or its super classes
  (declaration of 'java.nio.file.Path' appears in /apex/com.android.runtime/javalib/core-oj.jar)
	at ...lsp.kotlin.compiler.vfs.ListingJarFileSystem.findFileByPath
	at ...lsp.kotlin.compiler.modules.KtLibraryModuleKt.getVirtualFileForLibraryRoot
	at ...lsp.kotlin.compiler.modules.KtLibraryModule.computeFiles
	at ...lsp.kotlin.compiler.AbstractCompilationEnvironment.initialize
	at ...lsp.kotlin.compiler.CompilationEnvironment.<init>
	at ...lsp.kotlin.compiler.Compiler.<init>
	at ...lsp.kotlin.KotlinLanguageServer$ProjectCompilerLifecycle.build
	at ...lsp.kotlin.CompilerSession.update

Root cause

Path.of(String, String...) was introduced in Java 11. Android's runtime (core-oj.jar, loaded from /apex/com.android.runtime) does not expose it on many Android versions, so the call compiles fine against a newer JDK but throws NoSuchMethodError at runtime on the device.

The first failing call is in ListingJarFileSystem.findFileByPath, which makes the Kotlin LSP unusable because the library module files can never be resolved.

Solution

Use java.nio.file.Paths.get(...), which has existed since Java 7 and is supported on Android. The behavior is identical: Paths.get(String, String...) is what Path.of delegates to.

Changes

ListingJarFileSystem.kt

  • Add import java.nio.file.Paths
  • findFileByPath: Path.of(...) -> Paths.get(...) (the call in the stack trace)
  • handlerFor retry path: Path.of(key) -> Paths.get(key)
  • isCurrent: Path.of(handler.jarPath) -> Paths.get(handler.jarPath)

SourceFileIndexer.kt

  • Add import java.nio.file.Paths
  • indexSourceFile: Path.of(metadata.filePath) -> Paths.get(metadata.filePath)
  • analyzeDeclaration: Path.of(filePath) -> Paths.get(filePath)

Files changed

lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/index/SourceFileIndexer.kt   | 5 +++--
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/vfs/ListingJarFileSystem.kt   | 7 ++++---
2 files changed, 7 insertions(+), 5 deletions(-)

Testing

  • Open a Kotlin project on an Android device/emulator where Path.of is unavailable
  • Confirm CompilerSession no longer logs Kotlin project update failed
  • Confirm library modules resolve (completion/diagnostics work for dependencies)
  • Confirm source file indexing completes without NoSuchMethodError

Notes

  • Pure API substitution, no behavior change on platforms where Path.of already worked.
  • Other modules may contain the same pattern; a grep for Path.of( across Android-targeted code is recommended as a follow-up.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@atlassian

atlassian Bot commented Nov 26, 2026

Copy link
Copy Markdown

To enable Code Reviewer, link your GitHub account to your Atlassian account.

This is a one-time task that takes less than a minute. Once your account is linked, resubmit the pull request to trigger a code review.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

  • Fixes a Kotlin LSP crash on Android 10 with NoSuchMethodError for Path.of during project update (#2322).
  • Replaces Path.of(...) with Paths.get(...) in ListingJarFileSystem.kt (findFileByPath, handlerFor retry, isCurrent) and SourceFileIndexer.kt (FIR instance-resolution check and failure tag).
  • No public declaration changes. Diff: 2 files, +7/−5.

Risks:

  • No device or emulator validation. Library-module resolution and source indexing remain unverified.
  • No tests were reported.
  • Other Android-targeted modules may still call Path.of. They can fail the same way until a follow-up search and fix.

The Kotlin compiler indexer and JAR file system now use Paths.get instead of Path.of at the changed path-construction sites. Existing path handling and lookup logic remain unchanged.

Changes: Kotlin path construction

Layer / File(s) Summary
Replace Path.of calls
lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/index/SourceFileIndexer.kt, lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/vfs/ListingJarFileSystem.kt
The indexer and JAR file system use Paths.get for the updated path constructions. Existing resolution, normalization, retry, and cache-check logic remains unchanged.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: itsaky-adfa, hal-eisen-adfa

Merge Risk: Minimal · up to 60b67

This change replaces Path.of with Paths.get in the Kotlin LSP so it no longer crashes on Android runtimes that lack Path.of. Behavior elsewhere is unchanged. No concrete risk was found, though on-device validation has not been reported.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: replacing Path.of with Paths.get in the Kotlin LSP for Android compatibility. It matches the changeset and the linked issue. The conventional-commit prefix is acceptab…
Linked Issues check Passed Issue #2322 requires the Kotlin LSP to stop failing with NoSuchMethodError for Path.of(String, String...) during project update, so that library modules resolve. At the reviewed head, ListingJarFileSy…
Out of Scope Changes check Passed The PR changes two files in the Kotlin LSP compiler module (ListingJarFileSystem.kt and SourceFileIndexer.kt). Each change replaces a Path.of call with Paths.get and adds the matching import. No publi…
Description check Passed The description is directly related to the changeset. It states that the PR replaces every Path.of(...) call in the Kotlin LSP compiler module with Paths.get(...) to fix a NoSuchMethodError on Android…
Full details: Title check

Explanation

The title names the main change: replacing Path.of with Paths.get in the Kotlin LSP for Android compatibility. It matches the changeset and the linked issue. The conventional-commit prefix is acceptable and the title is specific.

Full details: Linked Issues check

Explanation

Issue #2322 requires the Kotlin LSP to stop failing with NoSuchMethodError for Path.of(String, String...) during project update, so that library modules resolve. At the reviewed head, ListingJarFileSystem.kt imports java.nio.file.Paths and uses Paths.get in findFileByPath (the first frame in the stack trace), in the handlerFor retry path, and in isCurrent. No Path.of call remains in that file. The change summary reports the same substitution in SourceFileIndexer.kt (indexSourceFile and analyzeDeclaration). The failing call path in the issue is covered. Paths.get(String, String...) is available on Android and is the method Path.of delegates to, so behavior is preserved. Residual uncertainty: the head was not read for SourceFileIndexer.kt, and the repository diff was unavailable, so the substitution there rests on the summary. No other module-wide Path.of call was verified, and the PR does not run device validation (its checklist is unchecked). Those checks are non-coding or outside the issue's stated Kotlin LSP scope.

Full details: Out of Scope Changes check

Explanation

The PR changes two files in the Kotlin LSP compiler module (ListingJarFileSystem.kt and SourceFileIndexer.kt). Each change replaces a Path.of call with Paths.get and adds the matching import. No public declarations or other behavior change, according to the file read and the change summary. These changes directly implement the objective in #2322. The PR states that other modules are follow-up work and does not include them, which keeps the scope limited.

Full details: Description check

Explanation

The description is directly related to the changeset. It states that the PR replaces every Path.of(...) call in the Kotlin LSP compiler module with Paths.get(...) to fix a NoSuchMethodError on Android runtimes. It names the affected call sites in ListingJarFileSystem.kt and SourceFileIndexer.kt, which match the raw summary. It also gives the root cause, the solution, the file list, and a testing checklist.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks each path at dawn,
And swaps the old constructor out.
The JAR paths now use Paths.get,
The indexer follows suit.
Then ears perk up: the crash is gone.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4a0bbf1d-0833-4b76-9856-1a8e014f232c
Commits

Reviewing files that changed from the base of the PR and between b0f479e and 60b677a.

Files selected for processing: 2

  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/index/SourceFileIndexer.kt
  • lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/vfs/ListingJarFileSystem.kt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kotlin lsp crashing with Android 10

1 participant