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

Eric Milles updated GROOVY-8363:
--------------------------------
    Labels: StackOverflowError  (was: )

> Implementing List with a delegated data source results in 
> StackOverflowException
> --------------------------------------------------------------------------------
>
>                 Key: GROOVY-8363
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8363
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Kevin Chen
>            Priority: Major
>              Labels: StackOverflowError
>
> Preface: not experienced with submitting bugs to the Groovy project, so 
> please bear with me if anything's unclear.
> I'm getting a StackOverflowException from this bit of code (I think just 
> including this snippet demonstrates better than I can explain verbally):
> {code:title=DelegateList.groovy|borderStyle=solid}
> class DelegateList {
>     private List<String> lowerCaseStrings = []
>     private DelegatingListImplementation uppercaseStrings = new 
> DelegatingListImplementation()
>     private abstract static class DelegatingList implements List<String> {
>         abstract List<String> getDelegate()
>         @Override
>         int size() {
>             return delegate.size()
>         }
>         @Override
>         boolean isEmpty() {
>             return delegate.isEmpty()
>         }
>         // etc.
>     }
>     private class DelegatingListImplementation extends DelegatingList {
>         @Override
>         List<String> getDelegate() {
>             return lowerCaseStrings.collect { it.toUpperCase() }
>         }
>     }
>     DelegateList(Collection<String> strings) {
>         lowerCaseStrings = strings.toList().collect { it.toLowerCase() }
>     }
>     List<String> getUppercase() {
>         return uppercaseStrings
>     }
>     public static void main(String[] args) {
>         def d = new DelegateList(['hello', 'bye'])
>         println d.getUppercase() // StackOverflowError
>     }
> }
> {code}
> The equivalent doesn't happen in Java. Example repository with both runnables 
> is here: [https://github.com/aspin/groovy-delegate-list]. I'm not really sure 
> how to get deeper into the source of this (Groovy's closure resolving 
> strategies?) and/or how to work around.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to