ktfmt: KFMT_idea_plugin crashes with Intellij 2024.3

Hello, the ktfmt_idea_plugin crashes with version 2024.3 of Intellij.

Steps to reproduce:

  • Install the plugin
  • format code with ctrl + alt + l

System:

  • Windows 11

Here is the stacktrace:

java.lang.ExceptionInInitializerError
	at com.facebook.ktfmt.format.Formatter.sortedAndDistinctImports(Formatter.kt:157)
	at com.facebook.ktfmt.format.Formatter.format(Formatter.kt:103)
	at com.facebook.ktfmt.intellij.KtfmtFormattingService$KtfmtFormattingTask.run(KtfmtFormattingService.kt:62)
	at com.intellij.formatting.service.AsyncDocumentFormattingService$FormattingRequestImpl.runTask(AsyncDocumentFormattingService.java:261)
	at com.intellij.formatting.service.AsyncDocumentFormattingService.runAsyncFormat(AsyncDocumentFormattingService.java:106)
	at com.intellij.formatting.service.AsyncDocumentFormattingService$FormattingProgressTask.run(AsyncDocumentFormattingService.java:380)
	at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:491)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:133)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$7(CoreProgressManager.java:542)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:249)
	at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:98)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:223)
	at com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.use(trace.kt:45)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:222)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$14(CoreProgressManager.java:674)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:749)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:705)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:673)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:203)
	at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:98)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$5(ProgressRunner.java:249)
	at com.intellij.openapi.progress.impl.ProgressRunner$ProgressRunnable.run(ProgressRunner.java:502)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$launchTask$18(ProgressRunner.java:467)
	at com.intellij.util.concurrency.ChildContext$runInChildContext$1.invoke(propagation.kt:101)
	at com.intellij.util.concurrency.ChildContext$runInChildContext$1.invoke(propagation.kt:101)
	at com.intellij.util.concurrency.ChildContext.runInChildContext(propagation.kt:107)
	at com.intellij.util.concurrency.ChildContext.runInChildContext(propagation.kt:101)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$launchTask$19(ProgressRunner.java:463)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:735)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:732)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:732)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.UnsupportedOperationException
	at java.base/sun.nio.fs.WindowsFileSystem.close(WindowsFileSystem.java:91)
	at com.intellij.platform.core.nio.fs.DelegatingFileSystem.close(DelegatingFileSystem.java:40)
	at org.jetbrains.kotlin.com.intellij.ide.plugins.DescriptorLoadingContext.close(DescriptorLoadingContext.java:49)
	at org.jetbrains.kotlin.com.intellij.ide.plugins.PluginManagerCore.registerExtensionPointAndExtensions(PluginManagerCore.java:1327)
	at org.jetbrains.kotlin.com.intellij.core.CoreApplicationEnvironment.registerExtensionPointAndExtensions(CoreApplicationEnvironment.java:287)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerApplicationExtensionPointsAndExtensionsFrom(KotlinCoreEnvironment.kt:625)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createApplicationEnvironment(KotlinCoreEnvironment.kt:595)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.getOrCreateApplicationEnvironment(KotlinCoreEnvironment.kt:505)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.getOrCreateApplicationEnvironmentForProduction(KotlinCoreEnvironment.kt:492)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:440)
	at com.facebook.ktfmt.format.Parser.<clinit>(Parser.kt:57)
	... 36 more

image

Thanks in advance 😃 Cheers, Olivier

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 22
  • Comments: 21 (8 by maintainers)

Commits related to this issue

Most upvoted comments

That’s awesome! Thanks everyone for reporting, for your help towards finding a fix and for the patience while we get it out there

It’s there ! Image

Also available inside Intellij from the marketplace !

And it works šŸ¾ 🤩

Really awesome !! Thanks a lot to all šŸ˜„

ktfmt is targeting Kotlin 1.8.22 whose compiler depends on an ancient IntelliJ platform SDK (203.8084.24). I bumped Kotlin to the latest stable version (2.1.0), built the plugin locally and it seems to work just fine. Not sure whether this is an acceptable solution though.

Released 0.54 that hopefully will fix this issue.

For now we’re on 2.0.0, but we are discussing pushing to the latest 2.0.x, which would be 2.0.21, as that would be quite similar to 2.0.0 except for some code fixes.

Right now we only bumped to 2.0.0 to try to make sure ktfmt is available for a broad range of use cases.

Awesome! Bumping it to 2.0.0 then. Let’s hope this fixes things

@hick209 Just ran a quick test and yeah, 2.0.0 works too. Verified on IntelliJ IDEA 2024.3.1.1 (243.22562.218).

@olivierbeltrandocintoo, it’s probably stuck in JB review process, which can take a while. According to Google up to 4 days, but usually it’s a couple of days from what I’ve seem with ktfmt

Image

@ezamelczyk, that’s actually a good idea for now, it’s just extra work. Do you happen to know or have pointers on how we could automate that? If we do this, it would be guaranteed to be there all the time

Just as info if not clear so far… Setting of K2 mode flag doesn’t matter - same issue independent of K2 mode setting.

In our team we are using IntelliJ IDEA Ultimate (2024.3.1.1 / #IU-243.22562.218), all on Windows. Happy to support.

Oh, I’m on macOS, could that be it? šŸ¤”

If so I might need help on this one since I don’t have a Windows machine

It only happens on Windows.

Version of Intellij:

  • IntelliJ IDEA 2024.3.1.1 (Community Edition)
  • Build #IC-243.22562.218, built on December 18, 2024

image

Version of the ktfmt plugin: 1.2.0.53 image

K2 is enabled image

Thanks a lot in advance for the help 😃