You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Marcelo Javier Glezer (Jira)" <ji...@apache.org> on 2022/07/07 13:16:00 UTC

[jira] [Created] (GROOVY-10681) Groovysh doesn't handle multiline strings with """ or ''' correctly

Marcelo Javier Glezer created GROOVY-10681:
----------------------------------------------

             Summary: Groovysh doesn't handle multiline strings with """ or ''' correctly
                 Key: GROOVY-10681
                 URL: https://issues.apache.org/jira/browse/GROOVY-10681
             Project: Groovy
          Issue Type: Bug
          Components: Groovysh
    Affects Versions: 3.0.11
         Environment: Mac M1
JVM: GraalVM CE 22.1.0 (17.0.3)
Groovy 3.0.9 / 3.0.10 / 3.0.11
            Reporter: Marcelo Javier Glezer


I've embedded a GroovySh console inside a server and using it works fine except when i try to parse multiline strings like:
a='''Hello
World'''
in the console it will fail as soon as i hit enter
{code:java}
console:000> a='''Hello
ERROR org.apache.groovy.parser.antlr4.GroovySyntaxError:
Unexpected character: '\'' {code}
and it will point to the third quote on line 1
 
On the server side i get this exception:
{code:java}
DEBUG [org.apache.groovy.groovysh.CommandsMultiCompleter] Refreshing the completer list
DEBUG [org.apache.groovy.groovysh.InteractiveShellRunner] Running
DEBUG [org.apache.groovy.groovysh.InteractiveShellRunner] Read line: a='''Hello
DEBUG [org.apache.groovy.groovysh.antlr4.RelaxedParser] Parsing:
a='''Hello
DEBUG [org.apache.groovy.groovysh.InteractiveShellRunner] Work failed: org.apache.groovy.parser.antlr4.GroovySyntaxError: Unexpected character: '\''
org.apache.groovy.parser.antlr4.GroovySyntaxError: Unexpected character: '\''
    at org.apache.groovy.parser.antlr4.SyntaxErrorReportable.throwSyntaxError(SyntaxErrorReportable.java:64)
    at org.apache.groovy.parser.antlr4.SyntaxErrorReportable.require(SyntaxErrorReportable.java:38)
    at org.apache.groovy.parser.antlr4.SyntaxErrorReportable.require(SyntaxErrorReportable.java:31)
    at org.apache.groovy.parser.antlr4.GroovyLexer.UNEXPECTED_CHAR_action(GroovyLexer.java:589)
    at org.apache.groovy.parser.antlr4.GroovyLexer.action(GroovyLexer.java:468)
    at groovyjarjarantlr4.v4.runtime.atn.LexerCustomAction.execute(LexerCustomAction.java:98)
    at groovyjarjarantlr4.v4.runtime.atn.LexerActionExecutor.execute(LexerActionExecutor.java:172)
    at groovyjarjarantlr4.v4.runtime.atn.LexerATNSimulator.accept(LexerATNSimulator.java:361)
    at groovyjarjarantlr4.v4.runtime.atn.LexerATNSimulator.failOrAccept(LexerATNSimulator.java:294)
    at groovyjarjarantlr4.v4.runtime.atn.LexerATNSimulator.execATN(LexerATNSimulator.java:229)
    at groovyjarjarantlr4.v4.runtime.atn.LexerATNSimulator.match(LexerATNSimulator.java:116)
    at groovyjarjarantlr4.v4.runtime.Lexer.nextToken(Lexer.java:142)
    at groovyjarjarantlr4.v4.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:170)
    at groovyjarjarantlr4.v4.runtime.BufferedTokenStream.fill(BufferedTokenStream.java:488)
    at groovyjarjarantlr4.v4.runtime.BufferedTokenStream$fill.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
    at org.apache.groovy.groovysh.antlr4.RelaxedParser.parse(RelaxedParser.groovy:50)
    at org.apache.groovy.groovysh.Parsing$parse.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
    at org.apache.groovy.groovysh.Parser.parse(Parser.groovy:67)
    at org.apache.groovy.groovysh.Parser$parse.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
    at org.apache.groovy.groovysh.Groovysh.execute(Groovysh.groovy:190)
    at org.apache.groovy.groovysh.Shell.leftShift(Shell.groovy:121)
    at org.apache.groovy.groovysh.Shell$leftShift$0.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
    at org.apache.groovy.groovysh.ShellRunner.work(ShellRunner.groovy:93)
    at org.apache.groovy.groovysh.InteractiveShellRunner.super$2$work(InteractiveShellRunner.groovy)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1268)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:144)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:164)
    at org.apache.groovy.groovysh.InteractiveShellRunner.work(InteractiveShellRunner.groovy:157)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:193)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:61)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:176)
    at org.apache.groovy.groovysh.ShellRunner.run(ShellRunner.groovy:57)
    at org.apache.groovy.groovysh.InteractiveShellRunner.super$2$run(InteractiveShellRunner.groovy)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1268)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:144)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:164)
    at org.apache.groovy.groovysh.InteractiveShellRunner.run(InteractiveShellRunner.groovy:116)
    at java_lang_Runnable$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
    at org.apache.groovy.groovysh.Groovysh.run(Groovysh.groovy:658)
    at pilot.server.console.GroovyShellCommand.lambda$start$0(GroovyShellCommand.java:112) {code}
 
I have discussed this over Slack with [~paulk] and he was able to reproduce this error. He commented that slashy strings works (and they do) 
{code:java}
a=/Hello
World/ {code}
and that the issue may be related to this fix: [https://github.com/apache/groovy/commit/c28da4be]
not been updated in GroovySh.
 
You can check the whole conversation over slack (thread) here:
[https://groovy-community.slack.com/archives/C2NEFCM55/p1657102392749539] 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)