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 fails to run on JDK 15 #1063

Closed
Assignees
Labels
Milestone

Comments

@Tapchicoma
Copy link
Collaborator

Expected Behavior

KtLint fails to run on JDK 15

Observed Behavior

TBA

Steps to Reproduce

  • Use JDK version 15
  • run KtLint check via CLI

Kotlin added JDK support in 1.4.20 version. Update is blocked, because CLI fails to run with this Kotlin version.

@BraisGabin
Copy link

BraisGabin commented Jan 17, 2021

Kotlin added JDK support in 1.4.20 version. Update is blocked, because CLI fails to run with this Kotlin version.

Do you have more information about this? We are having exactly the same problem in detekt. Detekt and ktlint raise different exceptions but the problem seems the same: The executable retuned by shadowJaraExecutable fails when you run in on Java8. But it works with Java9 and onwards.

And it's not related with the compilation JDK.

ktlint:

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:567)
	at com.pinterest.ktlint.KtlintCommandLine.parallel$default(Main.kt:541)
	at com.pinterest.ktlint.KtlintCommandLine.lintFiles(Main.kt:290)
	at com.pinterest.ktlint.KtlintCommandLine.run(Main.kt:256)
	at com.pinterest.ktlint.Main.main(Main.kt:69)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.pinterest.ktlint.core.KtLint
	at com.pinterest.ktlint.internal.FileUtilsKt.lintFile(FileUtils.kt:71)
	at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:387)
	at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:124)
	at com.pinterest.ktlint.KtlintCommandLine$lintFiles$2$1.call(Main.kt:281)
	at com.pinterest.ktlint.KtlintCommandLine$lintFiles$2$1.call(Main.kt:124)
	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)

detekt:

java.lang.RuntimeException: java.util.zip.ZipException: invalid block type
	at org.jetbrains.kotlin.com.intellij.util.ExceptionUtil.rethrow(ExceptionUtil.java:116)
	at org.jetbrains.kotlin.com.intellij.ide.plugins.PluginManagerCore.loadDescriptorFromJar(PluginManagerCore.java:900)
	at org.jetbrains.kotlin.com.intellij.ide.plugins.PluginManagerCore.registerExtensionPointAndExtensions(PluginManagerCore.java:1867)
	at org.jetbrains.kotlin.com.intellij.core.CoreApplicationEnvironment.registerExtensionPointAndExtensions(CoreApplicationEnvironment.java:265)
	at org.jetbrains.kotlin.cli.jvm.compiler.CoreApplicationEnvironmentCompatKt.registerExtensionPointAndExtensionsEx(coreApplicationEnvironmentCompat.kt:17)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerApplicationExtensionPointsAndExtensionsFrom(KotlinCoreEnvironment.kt:537)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createApplicationEnvironment(KotlinCoreEnvironment.kt:508)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.getOrCreateApplicationEnvironmentForProduction(KotlinCoreEnvironment.kt:465)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:419)
	at io.github.detekt.parser.KotlinEnvironmentUtilsKt.createKotlinCoreEnvironment(KotlinEnvironmentUtils.kt:44)
	at io.gitlab.arturbosch.detekt.core.settings.EnvironmentFacade$environment$2.invoke(EnvironmentAware.kt:38)
	at io.gitlab.arturbosch.detekt.core.settings.EnvironmentFacade$environment$2.invoke(EnvironmentAware.kt:22)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at io.gitlab.arturbosch.detekt.core.settings.EnvironmentFacade.getEnvironment(EnvironmentAware.kt)
	at io.gitlab.arturbosch.detekt.core.ProcessingSettings.getEnvironment(ProcessingSettings.kt)
	at io.gitlab.arturbosch.detekt.core.KtTreeCompiler.<init>(KtTreeCompiler.kt:14)
	at io.gitlab.arturbosch.detekt.core.tooling.ParsingStrategyKt$inputPathsToKtFiles$1.invoke(ParsingStrategy.kt:24)
	at io.gitlab.arturbosch.detekt.core.tooling.ParsingStrategyKt$inputPathsToKtFiles$1.invoke(ParsingStrategy.kt)
	at io.gitlab.arturbosch.detekt.core.tooling.Lifecycle$analyze$filesToAnalyze$1.invoke(Lifecycle.kt:34)
	at io.gitlab.arturbosch.detekt.core.tooling.Lifecycle$analyze$filesToAnalyze$1.invoke(Lifecycle.kt:22)
	at io.gitlab.arturbosch.detekt.core.util.PerformanceMonitor.measure(PerformanceMonitor.kt:42)
	at io.gitlab.arturbosch.detekt.core.tooling.Lifecycle$DefaultImpls.measure(Lifecycle.kt:30)
	at io.gitlab.arturbosch.detekt.core.tooling.Lifecycle$DefaultImpls.analyze(Lifecycle.kt:34)
	at io.gitlab.arturbosch.detekt.core.tooling.DefaultLifecycle.analyze(Lifecycle.kt:57)
	at io.gitlab.arturbosch.detekt.core.tooling.AnalysisFacade$runAnalysis$1.invoke(AnalysisFacade.kt:43)
	at io.gitlab.arturbosch.detekt.core.tooling.AnalysisFacade$runAnalysis$1.invoke(AnalysisFacade.kt:21)
	at io.gitlab.arturbosch.detekt.core.tooling.ProcessingSpecSettingsBridgeKt.withSettings(ProcessingSpecSettingsBridge.kt:26)
	at io.gitlab.arturbosch.detekt.core.tooling.AnalysisFacade.runAnalysis$detekt_core(AnalysisFacade.kt:42)
	at io.gitlab.arturbosch.detekt.core.tooling.AnalysisFacade.run(AnalysisFacade.kt:25)
	at io.gitlab.arturbosch.detekt.cli.runners.Runner.call(Runner.kt:33)
	at io.gitlab.arturbosch.detekt.cli.CliRunner.run(CliRunner.kt:33)
	at io.gitlab.arturbosch.detekt.cli.CliRunner.run(CliRunner.kt:15)
	at io.gitlab.arturbosch.detekt.cli.Main.main(Main.kt:19)
Caused by: java.util.zip.ZipException: invalid block type
	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:117)
	at org.jetbrains.kotlin.com.intellij.openapi.util.JDOMUtil.load(JDOMUtil.java:345)
	at org.jetbrains.kotlin.com.intellij.ide.plugins.PluginManagerCore.loadDescriptorFromJar(PluginManagerCore.java:880)
	... 31 more

@Tapchicoma
Copy link
Collaborator Author

@BraisGabin this what I see after updating KtLint to Kotlin 1.4.20+ and running it via CLI. If I run using java -jar ktlint-shadown-cli.jar then everything is ok.

From my not-so-deep investigation, something was changed in embeddable Kotlin compiler initialization internals that causing this.

@Tapchicoma Tapchicoma added this to the 0.41.0 milestone Jan 18, 2021
@Tapchicoma
Copy link
Collaborator Author

@BraisGabin check PR for CLI crash workaround. Not the best solution, but it works 🤷‍♂️

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