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

TypeChecked/CompileStatic: IndexOutOfBoundsException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.6
    • Fix Version/s: 2.4.7
    • Component/s: Compiler
    • Labels:
      None

      Description

      Compiling the following:

      IOOBE.groovy
      import groovy.transform.TypeChecked
      
      import java.nio.file.Files
      import java.nio.file.Paths
      
      @TypeChecked
      class IOOBE
      {
        def ioobe()
        {
          Files.write(Paths.get('foo.bar'), { ['foo', 'bar'].iterator() });
        }
      }
      

      (closure is used to automatically coerce Iterator to Iterable),
      produces the following exception during compilation:

      Error:Groovyc: java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
      	at java.util.LinkedList.checkElementIndex(LinkedList.java:555)
      	at java.util.LinkedList.get(LinkedList.java:476)
      	at org.codehaus.groovy.ast.expr.TupleExpression.getExpression(TupleExpression.java:89)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferSAMType(StaticTypeCheckingVisitor.java:2342)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferClosureParameterTypes(StaticTypeCheckingVisitor.java:2318)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallArguments(StaticTypeCheckingVisitor.java:2282)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallExpression(StaticTypeCheckingVisitor.java:2970)
      	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:66)
      	at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:71)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:196)
      	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
      	at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:37)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:166)
      	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:104)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:115)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:1774)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:126)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2107)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2066)
      	at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1086)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:53)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:249)
      	at org.codehaus.groovy.transform.StaticTypesTransformation.visit(StaticTypesTransformation.java:66)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:134)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor$2.call(ASTTransformationVisitor.java:178)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1055)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
      	at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:62)
      	at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:115)
      	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:134)
      	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:156)
      	at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.access$000(InProcessGroovyc.java:51)
      	at org.jetbrains.jps.incremental.groovy.InProcessGroovyc$1.call(InProcessGroovyc.java:85)
      	at org.jetbrains.jps.incremental.groovy.InProcessGroovyc$1.call(InProcessGroovyc.java:82)
      	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)
      

        Issue Links

          Activity

          Hide
          shils Shil Sinha added a comment -

          This occurs during SAM type inference when the target method has a var args parameter for which no argument is supplied - in this case Paths.write(Path, Iterable<? extends CharSequence>, OpenOptions...). The number of parameters being greater than the number of arguments causes the exception.

          Show
          shils Shil Sinha added a comment - This occurs during SAM type inference when the target method has a var args parameter for which no argument is supplied - in this case Paths.write(Path, Iterable<? extends CharSequence>, OpenOptions...) . The number of parameters being greater than the number of arguments causes the exception.
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user paulk-asert opened a pull request:

          https://github.com/apache/groovy/pull/339

          GROOVY-7784: TypeChecked/CompileStatic: IndexOutOfBoundsException

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/paulk-asert/groovy groovy7784

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/groovy/pull/339.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #339


          commit 2d1029f6b933a1bc45f6a6f0b3e8e62c5d29ed5c
          Author: paulk <paulk@asert.com.au>
          Date: 2016-05-26T13:27:55Z

          GROOVY-7784: TypeChecked/CompileStatic: IndexOutOfBoundsException


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user paulk-asert opened a pull request: https://github.com/apache/groovy/pull/339 GROOVY-7784 : TypeChecked/CompileStatic: IndexOutOfBoundsException You can merge this pull request into a Git repository by running: $ git pull https://github.com/paulk-asert/groovy groovy7784 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/groovy/pull/339.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #339 commit 2d1029f6b933a1bc45f6a6f0b3e8e62c5d29ed5c Author: paulk <paulk@asert.com.au> Date: 2016-05-26T13:27:55Z GROOVY-7784 : TypeChecked/CompileStatic: IndexOutOfBoundsException
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/groovy/pull/339

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/groovy/pull/339
          Hide
          paulk Paul King added a comment -

          PR merged

          Show
          paulk Paul King added a comment - PR merged

            People

            • Assignee:
              paulk Paul King
              Reporter:
              greg2001 Gregory Moltchadski
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development