[ 
https://issues.apache.org/jira/browse/GROOVY-9482?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King closed GROOVY-9482.
-----------------------------
    Resolution: Duplicate

Thanks for spotting that. We are aware of the issue (see GROOVY-9438) and 
already have a fix in place. We plan on releasing a new version with the fix in 
possibly about a week's time.

> Problem with empty case in switches when not in last position
> -------------------------------------------------------------
>
>                 Key: GROOVY-9482
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9482
>             Project: Groovy
>          Issue Type: Bug
>          Components: syntax
>    Affects Versions: 2.5.10
>         Environment: openjdk version "1.8.0_242" (zulu)
>            Reporter: Sylvain Dusart
>            Priority: Minor
>         Attachments: testcase.tgz
>
>
> There seems to be a problem with empty cases for switch with groovy 2.5.10 
> except when they are in the last position.
> {code}
> String s = ''
> switch (s) {
>   case 'a':
>       println s
>       break
>   // will generate a compilation error with groovy 2.5.10
>   case 'empty':
>         break
>   case 'b':
>         println s
>       break
> }
> {code}
> The exception is :
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:org.codehaus.groovy.control.MultipleCompilationErrorsException: 
> startup failed:General error during class generation: 
> org.codehaus.groovy.ast.stmt.ReturnStatement cannot be cast to 
> org.codehaus.groovy.ast.stmt.BlockStatement
> java.lang.ClassCastException: org.codehaus.groovy.ast.stmt.ReturnStatement 
> cannot be cast to org.codehaus.groovy.ast.stmt.BlockStatement at 
> org.codehaus.groovy.classgen.FinalVariableAnalyzer.fallsThrough(FinalVariableAnalyzer.java:480)
>  at 
> org.codehaus.groovy.classgen.FinalVariableAnalyzer.visitSwitch(FinalVariableAnalyzer.java:344)
>  at 
> org.codehaus.groovy.ast.stmt.SwitchStatement.visit(SwitchStatement.java:53) 
> at 
> org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:86)
>  at 
> org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:106)
>  at 
> org.codehaus.groovy.classgen.FinalVariableAnalyzer.visitBlockStatement(FinalVariableAnalyzer.java:147)
>  at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69) 
> at 
> org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:110)
>  at 
> org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:121)
>  at 
> org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:132)
>  at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1103) at 
> org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:54)
>  at 
> org.codehaus.groovy.classgen.Verifier.checkFinalVariables(Verifier.java:263) 
> at org.codehaus.groovy.classgen.Verifier.visitClass(Verifier.java:258) at 
> org.codehaus.groovy.control.CompilationUnit$18.call(CompilationUnit.java:811) 
> at 
> org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1084)
>  at 
> org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:640)
>  at 
> org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:618)
>  at 
> org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:595) 
> at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:401) at 
> groovy.lang.GroovyClassLoader.access$300(GroovyClassLoader.java:89) at 
> groovy.lang.GroovyClassLoader$5.provide(GroovyClassLoader.java:341) at 
> groovy.lang.GroovyClassLoader$5.provide(GroovyClassLoader.java:338) at 
> org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache.getAndPut(ConcurrentCommonCache.java:147)
>  at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:336) at 
> groovy.lang.GroovyShell.parseClass(GroovyShell.java:546) at 
> groovy.lang.GroovyShell.run(GroovyShell.java:375) at 
> groovy.lang.GroovyShell.run(GroovyShell.java:365) at 
> groovy.ui.GroovyMain.processOnce(GroovyMain.java:592) at 
> groovy.ui.GroovyMain.run(GroovyMain.java:336) at 
> groovy.ui.GroovyMain.access$1400(GroovyMain.java:69) at 
> groovy.ui.GroovyMain$GroovyCommand.process(GroovyMain.java:295) at 
> groovy.ui.GroovyMain.processArgs(GroovyMain.java:134) at 
> groovy.ui.GroovyMain.main(GroovyMain.java:116) at 
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:498) at 
> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:110) at 
> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
> 1 error {code}
> It works with groovy 2.5.9 and 3.0.2.
> In attachment, you'll find a small test case to reproduce the problem.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to