Nikolay Chashnikov created GROOVY-10458:
-------------------------------------------

             Summary: Path to a problematic file isn't shown in the error 
message sometimes if compilation fails with IndexOutOfBoundsException
                 Key: GROOVY-10458
                 URL: https://issues.apache.org/jira/browse/GROOVY-10458
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 3.0.9
            Reporter: Nikolay Chashnikov


Try compiling the following code in Groovy 3.0.9:
{code:groovy}
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic

@CompileStatic
class MyConstructorBug {
    @CompileDynamic
    MyConstructorBug() {
        new StringReader("abc").close()
    }
}
{code}
It'll fail with the exception (see below). Looks like this is caused by the 
same problems as GROOVY-10457, but in this case path to problematic file isn't 
included into the error message and isn't printed to the output. There is a 
code which should do this in 
org.codehaus.groovy.classgen.asm.OperandStack#popWithMessage, but it catches 
ArrayIndexOutOfBoundsException, whereas IndexOutOfBoundsException is actually 
thrown. Please change the catch statement in OperandStack#popWithMessage.

{noformat}
java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0
        at 
java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
        at 
java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
        at 
java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
        at java.base/java.util.Objects.checkIndex(Objects.java:372)
        at java.base/java.util.ArrayList.remove(ArrayList.java:536)
        at 
org.codehaus.groovy.classgen.asm.OperandStack.popWithMessage(OperandStack.java:110)
        at 
org.codehaus.groovy.classgen.asm.OperandStack.remove(OperandStack.java:218)
        at 
org.codehaus.groovy.classgen.asm.OperandStack.replace(OperandStack.java:292)
        at 
org.codehaus.groovy.classgen.asm.InvocationWriter.makeUncachedCall(InvocationWriter.java:374)
        at 
org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:387)
        at 
org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:121)
        at 
org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:649)
        at 
org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:456)
        at 
org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:140)
        at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:839)
        at 
org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:76)
        at 
org.codehaus.groovy.classgen.asm.StatementWriter.writeExpressionStatement(StatementWriter.java:635)
        at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitExpressionStatement(AsmClassGenerator.java:687)
        at 
org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
        at 
org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:94)
        at 
org.codehaus.groovy.classgen.asm.sc.StaticTypesStatementWriter.writeBlockStatement(StaticTypesStatementWriter.java:78)
        at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:618)
        at 
org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:138)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:111)
        at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:462)
        at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:409)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructor(ClassCodeVisitorSupport.java:101)
        at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructor(AsmClassGenerator.java:551)
        at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1089)
        at 
org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)
        at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:272)
        at 
org.codehaus.groovy.control.CompilationUnit$3.call(CompilationUnit.java:797)
        at 
org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:942)
        at 
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671)
        at 
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)
        at 
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:610)
{noformat}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to