Christopher Hobbs created GROOVY-7463:
-----------------------------------------

             Summary: break to labelled if fails
                 Key: GROOVY-7463
                 URL: https://issues.apache.org/jira/browse/GROOVY-7463
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 2.4.3
            Reporter: Christopher Hobbs


The following java code compiles:
{code}
package com.example;

public class Main {

    public static void main(String[] args) {
        LABEL:
        if (true) {
            System.out.println("1");
            if (true) break LABEL;
            System.out.println("2");
        }
        System.out.println("3");
    }
}
{code}

meanwhile the same code in groovy fails to compile with the error {{Error:(12, 
23) Groovyc: the break statement with named label is only allowed inside 
loops}}.

In the code where I originally found this error, the compiler throws an 
exception:
{code}
Error:Groovyc: BUG! exception in phase 'class generation' in source unit 
'/data/programming/jMinecraftLib/src/main/groovy/uk/co/rx14/jlaunchlib/caches/MinecraftMaven.groovy'
 unexpected NullpointerException
        at 
org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1057)
        at 
org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:588)
        at 
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:566)
        at 
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:543)
        at 
org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:58)
        at 
org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.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:497)
        at 
org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:132)
        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:497)
        at 
org.jetbrains.jps.incremental.groovy.InProcessGroovyc.runGroovycInThisProcess(InProcessGroovyc.java:148)
        at 
org.jetbrains.jps.incremental.groovy.InProcessGroovyc.access$000(InProcessGroovyc.java:48)
        at 
org.jetbrains.jps.incremental.groovy.InProcessGroovyc$1.call(InProcessGroovyc.java:77)
        at 
org.jetbrains.jps.incremental.groovy.InProcessGroovyc$1.call(InProcessGroovyc.java:74)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
        at 
org.codehaus.groovy.control.LabelVerifier.visitBreakStatement(LabelVerifier.java:123)
        at 
org.codehaus.groovy.ast.stmt.BreakStatement.visit(BreakStatement.java:44)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitIfElse(CodeVisitorSupport.java:56)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitIfElse(ClassCodeVisitorSupport.java:203)
        at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:41)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:163)
        at 
org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitIfElse(CodeVisitorSupport.java:56)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitIfElse(ClassCodeVisitorSupport.java:203)
        at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:41)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:163)
        at 
org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitClosureExpression(CodeVisitorSupport.java:174)
        at 
org.codehaus.groovy.ast.expr.ClosureExpression.visit(ClosureExpression.java:43)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitListOfExpressions(CodeVisitorSupport.java:273)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitTupleExpression(CodeVisitorSupport.java:178)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitArgumentlistExpression(CodeVisitorSupport.java:283)
        at 
org.codehaus.groovy.ast.expr.ArgumentListExpression.visit(ArgumentListExpression.java:74)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitMethodCallExpression(CodeVisitorSupport.java:131)
        at 
org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:64)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitReturnStatement(CodeVisitorSupport.java:73)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitReturnStatement(ClassCodeVisitorSupport.java:208)
        at 
org.codehaus.groovy.ast.stmt.ReturnStatement.visit(ReturnStatement.java:47)
        at 
org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:163)
        at 
org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:101)
        at 
org.codehaus.groovy.control.LabelVerifier.visitClassCodeContainer(LabelVerifier.java:63)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:112)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
        at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1083)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
        at 
org.codehaus.groovy.control.CompilationUnit$16.call(CompilationUnit.java:783)
        at 
org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1052)
        ... 22 more
{code}

I have been unable to reproduce the compiler exception outside of the project 
where I found it.

Should breaking out of an if work? It certainly shouldn't create a compiler 
exception.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to