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

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

blackdrag commented on PR #3330:
URL: https://github.com/apache/groovy/pull/3330#issuecomment-7095260318

   @daniellansun consider this:
   ```groovy
   def nestedList1 = [1]
   nestedList1 << [nestedList1]
   
   def nestedList2 = [2]
   nestedList2 << [nestedList2]
   
   def nestedList3 = [3]
   
   def nestedList4 = [nestedList1, nestedList2, nestedList3]
   
   assert nestedList4.toString() == '[[1, [(this Collection)]], [2, [(this 
Collection)]], [3]]'
   nestedList3 << nestedList4
   assert nestedList4.toString() == '[[1, [(this Collection)]], [2, [(this 
Collection)]], [3, (this Collection)]]'
   ```
   Does this kind of output make any sense to you? "this Collection" was kind 
of fine, for when we did try to detect root nested in root. But your new PR 
goes deeper and then "this Collection" is very unclear




> 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