Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10458

Path to a problematic file isn't shown in the error message sometimes if compilation fails with IndexOutOfBoundsException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.9
    • 2.5.16, 3.0.10, 4.0.1
    • Compiler
    • None

    Description

      Try compiling the following code in Groovy 3.0.9:

      import groovy.transform.CompileDynamic
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class MyConstructorBug {
          @CompileDynamic
          MyConstructorBug() {
              new StringReader("abc").close()
          }
      }
      

      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.

      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)
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              chashnikov Nikolay Chashnikov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: