live-plugin icon indicating copy to clipboard operation
live-plugin copied to clipboard

Groovy hello-world fails in 2024.3

Open rakete opened this issue 1 year ago • 10 comments

Seems like none of the groovy examples work:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:file:/C:/Users/Rakete/AppData/Roaming/JetBrains/Rider2024.3/live-plugins/hello-world/plugin.groovy: 1: Unexpected character: '' @ line 1, column 1.   import com.intellij.openapi.diagnostic.Logger   ^1 error
	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:292)
	at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:148)
	at org.apache.groovy.parser.antlr4.AstBuilder.collectSyntaxError(AstBuilder.java:4321)
	at org.apache.groovy.parser.antlr4.AstBuilder.createParsingFailedException(AstBuilder.java:4304)
	at org.apache.groovy.parser.antlr4.AstBuilder.convertException(AstBuilder.java:261)
	at org.apache.groovy.parser.antlr4.AstBuilder.buildCST(AstBuilder.java:235)
	at org.apache.groovy.parser.antlr4.AstBuilder.buildAST(AstBuilder.java:269)
	at org.apache.groovy.parser.antlr4.Antlr4ParserPlugin.buildAST(Antlr4ParserPlugin.java:58)
	at org.codehaus.groovy.control.SourceUnit.buildAST(SourceUnit.java:256)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1939)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
	at org.codehaus.groovy.control.CompilationUnit.buildASTs(CompilationUnit.java:667)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:633)
	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389)
	at groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332)
	at org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
	at org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330)
	at groovy.util.GroovyScriptEngine$ScriptClassLoader.doParseClass(GroovyScriptEngine.java:232)
	at groovy.util.GroovyScriptEngine$ScriptClassLoader.parseClass(GroovyScriptEngine.java:219)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:314)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:257)
	at groovy.util.GroovyScriptEngine.loadScriptByName(GroovyScriptEngine.java:529)
	at liveplugin.implementation.pluginrunner.groovy.GroovyPluginRunner.setup(GroovyPluginRunner.kt:54)
	at liveplugin.implementation.pluginrunner.PluginRunnerKt.runWith$lambda$5(PluginRunner.kt:161)
	at liveplugin.implementation.pluginrunner.PluginRunnerKt$runInBackground$2.run(PluginRunner.kt:176)
	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)

rakete avatar Jan 04 '25 17:01 rakete

I tried Rider 2024.3.3 on macOS with LivePlugin 0.9.5 and Groovy examples work fine.

Looking at the stack trace, it's Groovy parser complaining about the first character in the file Unexpected character: '' @ line 1, column 1, so I wonder if it could be related to the file encoding, e.g. https://en.wikipedia.org/wiki/Byte_order_mark 🤔

dkandalov avatar Jan 04 '25 22:01 dkandalov

Maybe, all I did was install the plugin, and click on the hello-world example and tried to run it. Groovy failed, but Kotlin worked fine and in the end I ended up creating this: https://gist.github.com/rakete/ca02db2000e1cf122c083773e4045190

I also tried some of the linked examples from the readme, some of which were written in groovy as well, and those failed as well. So I assume groovy just doesn't work on windows. Encoding issues is probably a good guess.

I also tried just one import line alone, thinking maybe that works, but same error. Then I gave up on Groovy.

rakete avatar Jan 05 '25 03:01 rakete

Thank you for sharing the Gist! (I don't get to see usages of LivePlugin very often :))

I think Rider should show detected encoding of the current file in the bottom right corner of the window (below the editor). Groovy does work on Windows (at least on the Windows 11 machine that I use), so it must be something else 🤔

dkandalov avatar Jan 05 '25 22:01 dkandalov

When I load either the kotlin or groovy hello-world the encoding starts out as UTF-8, kotlin works, groovy fails.

When I convert the encoding of the groovy hello-world to US-ASCII (there is some kind of popup where I clicked "Convert"), it works! And when I change it back to UTF-8 then it still works even (no popup asking me to convert then).

rakete avatar Jan 06 '25 02:01 rakete

When I load either the kotlin or groovy hello-world the encoding starts out as UTF-8, kotlin works, groovy fails.

Just to confirm, when you do Add Plugin -> Groovy Example -> hello-world, Rider shows encoding of plugin.groovy as UTF-8 but Groovy fails?

This is interesting because plugin.groovy is bundled in LivePlugin without BOM, so most likely it's added when writing file to disk (maybe Rider uses BOM by default), this is the equivalent code in Kotlin:

import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.vfs.VfsUtil
import liveplugin.show

runWriteAction {
    val dir = VfsUtil.createDirectoryIfMissing("/tmp/foo")!!
    val file = dir.createChildData(null, "bar")
    VfsUtil.saveText(file, "some text")
    show(file.charset)
}

Another option is that LivePlugin.zip is modified at some point 😨 (I should probably publish checksums just in case!)

dkandalov avatar Jan 06 '25 10:01 dkandalov

Yep, I do Add Plugin -> Groovy Example -> <any example> and Rider shows the file as UTF-8 encoded, but I always get the same error.

https://github.com/user-attachments/assets/ba5afe15-4357-493b-82e5-f9d71374ba85

I picked one that I did not try yet, instead of hello-world, but it is always the same error.

Here is the plugin.groovy: plugin.zip

Also I opened the file in Notepad++ and it shows the encoding as UTF-8-BOM, so UTF-8 but with some extra bytes at the beginning. Maybe it's actually a bug of Rider not understanding UTF-8-BOM.

rakete avatar Jan 06 '25 19:01 rakete

When I share a kotlin plugin as gist and then use the url to add the plugin to another jetbrains IDE I get this:

zwnbsp

at the beginning of the file.

If I don't remove the ZWNBSP the plugin won't work.

rakete avatar Jan 07 '25 02:01 rakete

Yes, this is the BOM. Do you mind running this code (it should match "charset configured in Settings|File Encodings|IDE encoding"):

import com.intellij.openapi.vfs.encoding.EncodingRegistry
import liveplugin.show

show(EncodingRegistry.getInstance().defaultCharset)

dkandalov avatar Jan 07 '25 13:01 dkandalov

When I make a new Kotlin live plugin and paste that code in and run it, I get a notification that says "UTF-8".

test

rakete avatar Jan 08 '25 20:01 rakete

Just a small update on this, I've been running into tons of other issues because of Jetbrains on Windows inserting a BOM by default. And I figured out that this behaviour can disabled actually.

Just search for BOM in settings, or go to Editor->File Encodings and in there the setting "Create UTF-8 files" has "with BOM under Windows, with no BOM otherwise" as default. Change that to "with NO BOM" to make Jetbrains not add a BOM.

rakete avatar Mar 23 '25 20:03 rakete