Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KtLint CLI 0.43 doesn't work with JDK 1.8 #1271

Closed
JajaComp opened this issue Nov 3, 2021 · 21 comments
Closed

KtLint CLI 0.43 doesn't work with JDK 1.8 #1271

JajaComp opened this issue Nov 3, 2021 · 21 comments
Assignees
Labels

Comments

@JajaComp
Copy link

JajaComp commented Nov 3, 2021

Gentoo linux latest
Ktlint 0.43 binary from you repository
Run in clean kotlin project

Command:
git diff --name-only --cached --relative | grep '\.kt[s"]\?$' | xargs ktlint --relative

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at com.pinterest.ktlint.KtlintCommandLine.parallel(Main.kt:576)
        at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:548)
        at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:298)
        at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:262)
        at com.pinterest.ktlint.Main.main(Main.kt:70)
Caused by: java.lang.ExceptionInInitializerError
        at com.pinterest.ktlint.internal.FileUtilsKt.lintFile(FileUtils.kt:172)
        at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:395)
        at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-0(Main.kt:289)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.util.zip.ZipException: invalid distance too far back
        at org.jetbrains.kotlin.com.intellij.util.ExceptionUtil.rethrow(ExceptionUtil.java:116)
        at org.jetbrains.kotlin.com.intellij.ide.plugins.PluginDescriptorLoader.loadDescriptorFromJar(PluginDescriptorLoader.java:107)
        at org.jetbrains.kotlin.com.intellij.ide.plugins.PluginManagerCore.registerExtensionPointAndExtensions(PluginManagerCore.java:1401)
        at org.jetbrains.kotlin.com.intellij.core.CoreApplicationEnvironment.registerExtensionPointAndExtensions(CoreApplicationEnvironment.java:266)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerApplicationExtensionPointsAndExtensionsFrom(KotlinCoreEnvironment.kt:575)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createApplicationEnvironment(KotlinCoreEnvironment.kt:540)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.getOrCreateApplicationEnvironment(KotlinCoreEnvironment.kt:497)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.getOrCreateApplicationEnvironmentForProduction(KotlinCoreEnvironment.kt:485)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:429)
        at com.pinterest.ktlint.core.internal.KotlinPsiFileFactoryKt.initPsiFileFactory(KotlinPsiFileFactory.kt:32)
        at com.pinterest.ktlint.core.KtLint.<clinit>(KtLint.kt:42)
        ... 8 more
Caused by: java.util.zip.ZipException: invalid distance too far back
        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
        at org.jetbrains.kotlin.com.intellij.openapi.vfs.CharsetToolkit.inputStreamSkippingBOM(CharsetToolkit.java:116)
        at org.jetbrains.kotlin.com.intellij.openapi.util.JDOMUtil.load(JDOMUtil.java:351)
        at org.jetbrains.kotlin.com.intellij.ide.plugins.PluginDescriptorLoader.loadDescriptorFromJar(PluginDescriptorLoader.java:87)
        ... 17 more

Command:
git diff --name-only --cached --relative | grep '\.kt[s"]\?$' | xargs ktlint .

Error:

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class com.pinterest.ktlint.core.KtLint
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at com.pinterest.ktlint.KtlintCommandLine.parallel(Main.kt:576)
        at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:548)
        at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:298)
        at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:262)
        at com.pinterest.ktlint.Main.main(Main.kt:70)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.pinterest.ktlint.core.KtLint
        at com.pinterest.ktlint.internal.FileUtilsKt.lintFile(FileUtils.kt:172)
        at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:395)
        at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-0(Main.kt:289)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

Command:
ktlint

Error:

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class com.pinterest.ktlint.core.KtLint
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at com.pinterest.ktlint.KtlintCommandLine.parallel(Main.kt:576)
        at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:548)
        at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:298)
        at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:262)
        at com.pinterest.ktlint.Main.main(Main.kt:70)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.pinterest.ktlint.core.KtLint
        at com.pinterest.ktlint.internal.FileUtilsKt.lintFile(FileUtils.kt:172)
        at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:395)
        at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
        at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-0(Main.kt:289)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
@JajaComp JajaComp changed the title Broken git hook action in 0.43 Broken 0.43 Nov 3, 2021
@paul-dingemans
Copy link
Collaborator

Please provide a sample file which causes this problem.

@JajaComp
Copy link
Author

JajaComp commented Nov 3, 2021

I can't provide my work project. but this problem i have in some my work projects on android / kotlin

@paul-dingemans
Copy link
Collaborator

Maybe you can strip a file in which the problem occurs to a bare minimum so that you do not have to provide any proprietary code. I can not investigate this without an example that causes this problem.

@JajaComp
Copy link
Author

JajaComp commented Nov 4, 2021

Just i create file "/tmp/3/test.kt" and fill him random data.
Next run "ktlint" without arguments and get error:

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at com.pinterest.ktlint.KtlintCommandLine.parallel(Main.kt:576)
	at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:548)
	at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:298)
	at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:262)
	at com.pinterest.ktlint.Main.main(Main.kt:70)
Caused by: java.lang.ExceptionInInitializerError
	at com.pinterest.ktlint.internal.FileUtilsKt.lintFile(FileUtils.kt:172)
	at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:395)
	at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
	at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-0(Main.kt:289)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.util.zip.ZipException: invalid distance too far back
	at org.jetbrains.kotlin.com.intellij.util.ExceptionUtil.rethrow(ExceptionUtil.java:116)
	at org.jetbrains.kotlin.com.intellij.ide.plugins.PluginDescriptorLoader.loadDescriptorFromJar(PluginDescriptorLoader.java:107)
	at org.jetbrains.kotlin.com.intellij.ide.plugins.PluginManagerCore.registerExtensionPointAndExtensions(PluginManagerCore.java:1401)
	at org.jetbrains.kotlin.com.intellij.core.CoreApplicationEnvironment.registerExtensionPointAndExtensions(CoreApplicationEnvironment.java:266)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerApplicationExtensionPointsAndExtensionsFrom(KotlinCoreEnvironment.kt:575)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createApplicationEnvironment(KotlinCoreEnvironment.kt:540)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.getOrCreateApplicationEnvironment(KotlinCoreEnvironment.kt:497)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.getOrCreateApplicationEnvironmentForProduction(KotlinCoreEnvironment.kt:485)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:429)
	at com.pinterest.ktlint.core.internal.KotlinPsiFileFactoryKt.initPsiFileFactory(KotlinPsiFileFactory.kt:32)
	at com.pinterest.ktlint.core.KtLint.<clinit>(KtLint.kt:42)
	... 8 more
Caused by: java.util.zip.ZipException: invalid distance too far back
	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
	at org.jetbrains.kotlin.com.intellij.openapi.vfs.CharsetToolkit.inputStreamSkippingBOM(CharsetToolkit.java:116)
	at org.jetbrains.kotlin.com.intellij.openapi.util.JDOMUtil.load(JDOMUtil.java:351)
	at org.jetbrains.kotlin.com.intellij.ide.plugins.PluginDescriptorLoader.loadDescriptorFromJar(PluginDescriptorLoader.java:87)
	... 17 more

@JajaComp
Copy link
Author

JajaComp commented Nov 4, 2021

Also when i create empty files:
/tmp/2/1/test.kt
/tmp/2/1/2/t2.kt
and run ktlint in "/tmp/2"
I got message:

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class com.pinterest.ktlint.core.KtLint
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at com.pinterest.ktlint.KtlintCommandLine.parallel(Main.kt:576)
	at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:548)
	at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:298)
	at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:262)
	at com.pinterest.ktlint.Main.main(Main.kt:70)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.pinterest.ktlint.core.KtLint
	at com.pinterest.ktlint.internal.FileUtilsKt.lintFile(FileUtils.kt:172)
	at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:395)
	at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
	at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-0(Main.kt:289)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Can't reproduce problem on apple m1. Only on linux x64

Also i can't reproduce problem on other linux x64 pc

Ktlint required java? On pc with problem version of java is:
openjdk version "1.8.0_302"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (Temurin)(build 25.302-b08, mixed mode)

@JajaComp
Copy link
Author

JajaComp commented Nov 4, 2021

I think problem really in java version:
~/soft/android-studio/jre/bin/java -jar ktlint work fine

~/soft/android-studio/jre/bin/java -version

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
OpenJDK 64-Bit Server VM (build 11.0.10+0-b96-7249189, mixed mode)

@Tapchicoma
Copy link
Collaborator

I cannot reproduce it on Gentoo with following JDK:

openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

@Tapchicoma
Copy link
Collaborator

If you just run java -version - what output you will see?

@JajaComp
Copy link
Author

JajaComp commented Nov 4, 2021

openjdk version "1.8.0_302"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (Temurin)(build 25.302-b08, mixed mode)

@Tapchicoma
Copy link
Collaborator

Yep, with JDK 1.8 I could reproduce it.

@Tapchicoma Tapchicoma added the bug label Nov 4, 2021
@Tapchicoma Tapchicoma self-assigned this Nov 4, 2021
@Tapchicoma Tapchicoma changed the title Broken 0.43 KtLint CLI 0.43 doesn't work with JDK 1.8 Nov 4, 2021
@orchestr7
Copy link
Contributor

orchestr7 commented Nov 8, 2021

Reproduced this with the latest ktlint. Let's pin this issue, so new people won't create duplicates?

Btw, it works fine with the jar from maven central. The problem is in the executable jar plugin (shadow). The following works fine:

java -jar ktlint-0.43.0-all.jar test.kt

@chenrui333
Copy link

Run into the same issue with the homebrew update

$ /usr/local/Cellar/ktlint/0.43.0/bin/ktlint -F In.kt
Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at com.pinterest.ktlint.KtlintCommandLine.parallel(Main.kt:576)
	at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:548)
	at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:298)
	at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:262)
	at com.pinterest.ktlint.Main.main(Main.kt:70)
Caused by: java.lang.ExceptionInInitializerError
	at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:201)
	at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:366)
	at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:89)
	at com.pinterest.ktlint.KtlintCommandLine$lintFiles$3.invoke$lambda-0(Main.kt:289)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.util.zip.ZipException: invalid distance too far back

@romtsn romtsn pinned this issue Nov 15, 2021
@GabrielLasso
Copy link

Here I have the following setup:

➜  ~ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
➜  ~ /opt/android-studio/jre/bin/java -version                        
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
OpenJDK 64-Bit Server VM (build 11.0.10+0-b96-7249189, mixed mode)

When I run just ktlint, it don't work, so my workaround is to run /opt/android-studio/jre/bin/java -jar /usr/bin/ktlint app/**/*.kt

@nfode
Copy link

nfode commented Nov 30, 2021

Hi, thx for fixing the issue. Is it planned to release a "bug fix" or a new minor version just containing the kotlin update, to solve this issue?

@Tapchicoma
Copy link
Collaborator

hopefully, new minor release soon will be done. Meanwhile you could try to use snapshot or build CLI yourself (run shadowJarExecutable task).

@shashachu
Copy link
Contributor

I'll work on pushing a minor release today.

@paul-dingemans
Copy link
Collaborator

I'll work on pushing a minor release today.
Please look at the list of ope PR's for other bug fixes related to version 0.43.0

@shashachu
Copy link
Contributor

@paul-dingemans thanks. I noticed you had a bunch of PRs open that I'll take a look at. If it's not too much trouble, could you link the ones that are 0.43.0 regressions? It's hard for me to tell which ones are existing issues and which ones we should consider for a minor release. We could also do an entirely new 0.44.0 release with a whole bunch of fixes if there are many, and only do a .1 release for the JDK fix.

@paul-dingemans
Copy link
Collaborator

@shashachu see or 1293, 1292, 1284, 1283, 1279 and 1276

@romtsn romtsn unpinned this issue Dec 1, 2021
@hongjisung
Copy link

In my case, temurin 1.8.0_322, adopt@1.8.0-292 works with 0.43.0.
But 0.43.2 makes error Cannot load extensions/core.xml

@initialjie
Copy link

0.46.1 still not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants