fwcd / fwcd/kotlin-language-server

Go-to-definition crashes when jar has plus sign in name

Open
#326 2 comments 1 reaction 0 assignees View on GitHub
bug dependency resolution
Dominant language
Kotlin
Stars
2k
Forks
252
PR merge metrics
No merged PRs in 30d

Description

Somewhere along the line, the plus in the `file://` URL is converted to a space, causing a crash by a `NoSuchFileException`.

I found this while writing a minecraft mod; I made a (mostly minimal) git repo to replicate the error: https://github.com/clarfonthey/kt-lsp-bug-repro

The following is the output I get from `kak-lsp` while attempting to go-to-definition for one of the sponge classes in `CrashReport_noopMixin.kt`. I additionally have the environment variable `CLASSPATH=/usr/share/kotlin/lib/*.jar` set.

```
*** This is the debug buffer, where debug info will be written ***
kak-lsp: config-change detected:
kak-lsp: log: main Adding script definitions [ScriptTemplateWithArgs]
kak-lsp: log: main Kotlin Language Server: Version 1.2.0
kak-lsp: log: main Connected to client
kak-lsp: log: async0 Adding workspace folder null
kak-lsp: log: async0 Adding .../minecraft-test/build.gradle.kts, .../minecraft-test/settings.gradle.kts, .../mixins/CrashReport_noopMixin.kt under /home/ltdk/minecraft-test to source path
kak-lsp: log: async0 Searching for dependencies and Java sources in workspace root /home/ltdk/minecraft-test
kak-lsp: log: async0 Resolving dependencies for 'minecraft-test' through Gradle's CLI using tasks [kotlinLSPProjectDeps]...
kak-lsp: log: async0 Found gradle at /usr/bin/gradle
kak-lsp: log: async0 Successfully resolved dependencies for 'minecraft-test' using Gradle
kak-lsp: log: async0 Resolving dependencies for 'minecraft-test' through Gradle's CLI using tasks [kotlinLSPProjectDeps]...
kak-lsp: log: async0 Found gradle at /usr/bin/gradle
kak-lsp: log: async0 Successfully resolved dependencies for 'minecraft-test' using Gradle
kak-lsp: log: async0 Adding 112 files to class path
kak-lsp: log: async0 Update build script path
kak-lsp: log: async0 Resolving dependencies for 'minecraft-test' through Gradle's CLI using tasks [kotlinLSPKotlinDSLDeps]...
kak-lsp: log: async0 Found gradle at /usr/bin/gradle
kak-lsp: language server is not initialized, parking request
kak-lsp: log: async0 Successfully resolved build script dependencies for 'minecraft-test' using Gradle
kak-lsp: log: async0 Adding 495 files to build script class path
kak-lsp: log: async0 Reinstantiating compiler
kak-lsp: log: async0 Adding script definitions [ScriptTemplateWithArgs]
kak-lsp: log: async0 Configuring Kotlin DSL script templates...
kak-lsp: log: async0 Adding script definitions [ScriptTemplateWithArgs, KotlinInitScript, KotlinSettingsScript, KotlinBuildScript]
kak-lsp: log: debounce0 Linting .../mixins/CrashReport_noopMixin.kt
kak-lsp: log: async2 Go-to-definition at .../mixins/CrashReport_noopMixin.kt 4:36
kak-lsp: log: async3 Updating symbol index...
kak-lsp: log: debounce0 Linting 0 files
kak-lsp: log: async2 Re-parsing CrashReport_noopMixin.kt 0:1-14:1
kak-lsp: log: async2 Hovering DOT_QUALIFIED_EXPRESSION
kak-lsp: log: async2 Found declaration descriptor Lazy Java class org.spongepowered.asm.mixin.Mixin
kak-lsp: log: async2 Finding contents of kls:file:///home/ltdk/.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.10.7%20mixin.0.8.4/7a4ca9d54d9ae564dea0363d668036a8420ed9b8/sponge-mixin-0.10.7%20mixin.0.8.4.jar!/org/spongepowered/asm/mixin/Mixin.class
kak-lsp: log: async2 Finished in 1389 ms
kak-lsp: log: async2 Internal error: java.nio.file.NoSuchFileException: /home/ltdk/.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.10.7 mixin.0.8.4/7a4ca9d54d9ae564dea0363d668036a8420ed9b8/sponge-mixin-0.10.7 mixin.0.8.4.jar
kak-lsp: log: java.util.concurrent.CompletionException: java.nio.file.NoSuchFileException: /home/ltdk/.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.10.7 mixin.0.8.4/7a4ca9d54d9ae564dea0363d668036a8420ed9b8/sponge-mixin-0.10.7 mixin.0.8.4.jar
kak-lsp: log: at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
kak-lsp: log: at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
kak-lsp: log: at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)
kak-lsp: log: at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
kak-lsp: log: at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
kak-lsp: log: at java.base/java.lang.Thread.run(Thread.java:833)
kak-lsp: log: Caused by: java.nio.file.NoSuchFileException: /home/ltdk/.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.10.7 mixin.0.8.4/7a4ca9d54d9ae564dea0363d668036a8420ed9b8/sponge-mixin-0.10.7 mixin.0.8.4.jar
kak-lsp: log: at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
kak-lsp: log: at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
kak-lsp: log: at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
kak-lsp: log: at java.base/sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
kak-lsp: log: at java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:149)
kak-lsp: log: at java.base/sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:99)
kak-lsp: log: at java.base/java.nio.file.Files.readAttributes(Files.java:1851)
kak-lsp: log: at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1264)
kak-lsp: log: at java.base/java.util.zip.ZipFile$CleanableResource.(ZipFile.java:709)
kak-lsp: log: at java.base/java.util.zip.ZipFile.(ZipFile.java:243)
kak-lsp: log: at java.base/java.util.zip.ZipFile.(ZipFile.java:172)
kak-lsp: log: at java.base/java.util.jar.JarFile.(JarFile.java:347)
kak-lsp: log: at java.base/sun.net.www.protocol.jar.URLJarFile.(URLJarFile.java:103)
kak-lsp: log: at java.base/sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:72)
kak-lsp: log: at java.base/sun.net.www.protocol.jar.JarFileFactory.getOrCreate(JarFileFactory.java:106)
kak-lsp: log: at java.base/sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:132)
kak-lsp: log: at java.base/sun.net.www.protocol.jar.JarURLConnection.getJarEntry(JarURLConnection.java:97)
kak-lsp: log: at org.javacs.kt.externalsources.KlsURI.extractToTemporaryFile(KlsURI.kt:104)
kak-lsp: log: at org.javacs.kt.externalsources.JarClassContentProvider.tryReadContentOf(JarClassContentProvider.kt:60)
kak-lsp: log: at org.javacs.kt.externalsources.JarClassContentProvider.contentOf(JarClassContentProvider.kt:42)
kak-lsp: log: at org.javacs.kt.definition.GoToDefinitionKt.goToDefinition(GoToDefinition.kt:48)
kak-lsp: log: at org.javacs.kt.KotlinTextDocumentService$definition$1.invoke(KotlinTextDocumentService.kt:129)
kak-lsp: log: at org.javacs.kt.KotlinTextDocumentService$definition$1.invoke(KotlinTextDocumentService.kt:124)
kak-lsp: log: at org.javacs.kt.util.AsyncExecutor.compute$lambda-2(AsyncExecutor.kt:19)
kak-lsp: log: at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
kak-lsp: log: ... 3 more
kak-lsp: kotlin language server error: 'Internal error.'
```

Focusing on the specific crash:

```
kak-lsp: log: async2 Internal error: java.nio.file.NoSuchFileException: /home/ltdk/.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.10.7 mixin.0.8.4/7a4ca9d54d9ae564dea0363d668036a8420ed9b8/sponge-mixin-0.10.7 mixin.0.8.4.jar
```

If you check out the file it's trying to access, you'll notice that the issue is it converting a plus sign to a space, which normally should only be done in query strings:

```diff
-.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.10.7 mixin.0.8.4/7a4ca9d54d9ae564dea0363d668036a8420ed9b8/sponge-mixin-0.10.7 mixin.0.8.4.jar
+.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.10.7+mixin.0.8.4/7a4ca9d54d9ae564dea0363d668036a8420ed9b8/sponge-mixin-0.10.7+mixin.0.8.4.jar
```

Not 100% sure what's happening here, but if you run `gradle build` by itself, it passes, meaning that the paths definitely are working in gradle internally.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at org.javacs.kt.externalsources.KlsURI.extractToTemporaryFile in KlsURI.kt:104 and follow JarClassContentProvider.kt:60. Reproduce go-to-definition with the linked Minecraft project and a jar whose name contains a plus sign; done means the jar is read successfully without NoSuchFileException or converting the plus to a space.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
developer-experience, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.