Repository navigation
fix(kotlin-lsp): use Android-compatible Path creation - #2324
Open
Wadamzmail wants to merge 1 commit into
Open
Wadamzmail wants to merge 1 commit into
Wadamzmail wants to merge 1 commit into
Conversation
|
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. |
Contributor
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.
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 everyPath.of(...)call in the Kotlin LSP compiler module withPaths.get(...), which is available on all Android versions.Problem
When the Kotlin project is updated,
CompilerSessioncrashes while building the compilation environment. The full stack trace is also attached in #2322: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 throwsNoSuchMethodErrorat 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 whatPath.ofdelegates to.Changes
ListingJarFileSystem.ktimport java.nio.file.PathsfindFileByPath:Path.of(...)->Paths.get(...)(the call in the stack trace)handlerForretry path:Path.of(key)->Paths.get(key)isCurrent:Path.of(handler.jarPath)->Paths.get(handler.jarPath)SourceFileIndexer.ktimport java.nio.file.PathsindexSourceFile:Path.of(metadata.filePath)->Paths.get(metadata.filePath)analyzeDeclaration:Path.of(filePath)->Paths.get(filePath)Files changed
Testing
Path.ofis unavailableCompilerSessionno longer logsKotlin project update failedNoSuchMethodErrorNotes
Path.ofalready worked.Path.of(across Android-targeted code is recommended as a follow-up.