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

Kevin Chen updated GROOVY-8363:
-------------------------------
    Description: 
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):
{{
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
    }
}
}}

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.


  was:
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):
{{
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
    }
}
}}

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.



> 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):
> {{
> 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
>     }
> }
> }}
> 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)

Reply via email to