[ 
https://issues.apache.org/jira/browse/GROOVY-7741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15135035#comment-15135035
 ] 

Shil Sinha edited comment on GROOVY-7741 at 2/5/16 9:31 PM:
------------------------------------------------------------

The closure passed to nodes.each calls itself in its doCall method instead of 
calling addTextClosure:

{code}
  public doCall(Ljava/lang/Object;)Ljava/lang/Object;
   L0
    LINENUMBER 11 L0
    ALOAD 0
    CHECKCAST ClosureStackOverflow$_f_closure2
    INVOKEVIRTUAL ClosureStackOverflow$_f_closure2.call ()Ljava/lang/Object;
    ARETURN
   L1
{code}

The exception does not occur if addTextClosure is called explicitly like 
{{addTextClosure.call()}}.


was (Author: shils):
The closure passed to nodes.each calls itself in its doCall method instead of 
calling addTextClosure:

{code}
  public doCall(Ljava/lang/Object;)Ljava/lang/Object;
   L0
    LINENUMBER 11 L0
    ALOAD 0
    CHECKCAST ClosureStackOverflow$_f_closure2
    INVOKEVIRTUAL ClosureStackOverflow$_f_closure2.call ()Ljava/lang/Object;
    ARETURN
   L1
{code}

> StackoverflowError with Closure and CompileStatic
> -------------------------------------------------
>
>                 Key: GROOVY-7741
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7741
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.5
>            Reporter: Gerhard Langs
>
> run the code below - it fails with a stackoverflow:
> {code}
> $ groovy ClosureStackOverflow.groovy
> Caught: java.lang.StackOverflowError
> java.lang.StackOverflowError
>         at ClosureStackOverflow$_f_closure2.call(ClosureStackOverflow.groovy)
>         at 
> ClosureStackOverflow$_f_closure2.doCall(ClosureStackOverflow.groovy:17)
>         at ClosureStackOverflow$_f_closure2.call(ClosureStackOverflow.groovy)
>         at 
> ClosureStackOverflow$_f_closure2.doCall(ClosureStackOverflow.groovy:17)
>         at ClosureStackOverflow$_f_closure2.call(ClosureStackOverflow.groovy)
>         at 
> ClosureStackOverflow$_f_closure2.doCall(ClosureStackOverflow.groovy:17)
> {code}
> {code}
> import groovy.transform.CompileStatic
> @CompileStatic
> class ClosureStackOverflow {
>     Closure addTextClosure = { "xx" }
>     void f()
>     {
>         List nodes = [ "sth" ]
>         nodes.each {
>             // here we get the overflow:
>             addTextClosure()
>         }
>     }
>     static void main(String[] args) {
>         new ClosureStackOverflow().f()
>     }
> }
> {code}



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

Reply via email to