[ 
https://issues.apache.org/jira/browse/GROOVY-11955?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King updated GROOVY-11955:
-------------------------------
    Labels:   (was: StackOverflowError)

> Provide a size guard for flattening of chained method calls
> -----------------------------------------------------------
>
>                 Key: GROOVY-11955
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11955
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Daniel Kuppitz
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 6.0.0-alpha-1, 5.0.5
>
>
> If the following statement is pasted into a Groovy shell, it's going to throw 
> a {{StackoverflowException}}:
> {code}
> static def generateSpec(def count) {
>     def assertions = (1..count).collect { i ->
>         "assert obj.field${i % 10} == 'value${i % 10}'"
>     }.join("\n\t\t\t\t")
>     def spec = """\
> @Grab('org.spockframework:spock-core:2.4-groovy-5.0')
> import spock.lang.Specification
> class MethodTooLargeReproducerSpec extends Specification {
>     def "verifyAll with ${count} assertions"() {
>         given:
>             def obj = [field0: 'value0', field1: 'value1', field2: 'value2',
>                        field3: 'value3', field4: 'value4', field5: 'value5',
>                        field6: 'value6', field7: 'value7', field8: 'value8',
>                        field9: 'value9']
>         expect:
>             verifyAll {
>             \t${assertions}
>             }
>     }
> }
> """
> }
> def gcl = new GroovyClassLoader()
> (589..597).step(1).each { count ->
>     def src = generateSpec(count)
>     try {
>         gcl.parseClass(src)
>         println "OK:     ${count}"
>     } catch (Exception e) {
>         println "FAILED: ${count} — ${e.message}"
>         System.exit(1)
>     }
> }
> {code}
> Trying to nail it to a certain number of method calls by starting with less 
> methods and then adding one at a time doesn't work, since that apparently 
> never throws an exception.
> Note that this is not tied to {{StringBuilder::append}}. We discovered this 
> issue in Gremlin, where it's pretty common to have a lot of chained method 
> calls.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to