groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Chen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8363) Implementing List with a delegated data source results in StackOverflowException
Date Mon, 23 Oct 2017 15:14:00 GMT

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

Kevin Chen commented on GROOVY-8363:
------------------------------------

Just threw on the @CompileStatic annotation and it doesn't change anything with the original
{{extends List<String>}} implementation.

> 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
>
> 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
(v6.4.14#64029)

Mime
View raw message