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

ASF GitHub Bot commented on GROOVY-3250:
----------------------------------------

daniellansun opened a new pull request, #3330:
URL: https://github.com/apache/groovy/pull/3330

   https://issues.apache.org/jira/browse/GROOVY-3250
   
   Nested and mixed `List`/`Map` cycles, and array cycles, overflowed when 
formatted with `toString`, `inspect`, `toListString`, `toMapString`, or 
`toArrayString`. Direct self-references already used the `(this Collection)` / 
`(this Map)` / `(this array)` markers; this change uses the same markers when a 
container is already on the current unbounded render path.
   
   Size-limited formatting still unrolls a structural cycle until the existing 
truncate applies, so results such as `animals.toListString(40)` stay the same.
   
   The render path is a thread-local identity set and is removed when the root 
render finishes, including if an element `toString` throws.
   
   `testGroovy3250` now runs as a regular test; its assertions are unchanged. 
Further cycle and cleanup coverage is in `GroovyMethodsTest` and 
`InvokerHelperFormattingTest`.
   




> StackOverflowError in List and Map formatting
> ---------------------------------------------
>
>                 Key: GROOVY-3250
>                 URL: https://issues.apache.org/jira/browse/GROOVY-3250
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 1.5.7
>         Environment: Groovy 1.5.7 and 1.6-RC1
>            Reporter: Alexander Veit
>            Assignee: Daniel Sun
>            Priority: Major
>              Labels: StackOverflowError
>
> If a List or Map that contains itself is formatted for output (print, 
> inspect,...) a StackOverflowError occurs.
> {code}
> import org.codehaus.groovy.runtime.InvokerHelper
> def x
> // List (simple case)
> x = []
> x << x
> assert "[(this Collection)]" == x.toString()
> InvokerHelper.toListString(x)
> // List (nested case)
> x = []
> x << [x]
> assert InvokerHelper.toListString(x)
> // Map (simple case)
> x = [:]
> x.put("self", x)
> assert "[self:this Map_]" == InvokerHelper.toMapString(x) // JDK uses "(this 
> Map)"
> // Map (nested case)
> x = [:]
> x.put("nested", ["self":x])
> assert InvokerHelper.toMapString(x)
> // there are also List/Map mixed cases
> // ...
> {code}
> See also GROOVY-1106.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to