[
https://issues.apache.org/jira/browse/GROOVY-7654?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16018962#comment-16018962
]
ASF GitHub Bot commented on GROOVY-7654:
----------------------------------------
GitHub user armsargis opened a pull request:
https://github.com/apache/groovy/pull/546
GROOVY-7654: Iterable as List and Iterable.asList() have different semantics
Introduce DefaultGroovyMethods.asType(Iterable, Class) to handle correctly
'asType' to iterables
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/armsargis/groovy GROOVY-7654
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/groovy/pull/546.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #546
----
commit faabd7bd65ef9437add8ce451f84a09066e0b448
Author: Sargis Harutyunyan <[email protected]>
Date: 2017-05-21T19:35:16Z
GROOVY-7654: Introduce DefaultGroovyMethods.asType(Iterable, Class) to
handle correctly 'asType' to iterables
----
> Iterable as List and Iterable.asList() have different semantics
> ---------------------------------------------------------------
>
> Key: GROOVY-7654
> URL: https://issues.apache.org/jira/browse/GROOVY-7654
> Project: Groovy
> Issue Type: Bug
> Components: groovy-jdk
> Affects Versions: 2.4.5
> Reporter: Shil Sinha
>
> For an Iterable `foo` which is not also a collection, `foo.asList()` and `foo
> as List` are not equivalent. The latter goes through the asType(Object,
> Class) path and ultimately returns a proxy. This is unexpected, and can
> result in some inconsistencies. A simple example:
> {code}
> class IterableWrapper implements Iterable {
> Iterable delegate
> Iterator iterator() {
> delegate.iterator()
> }
> }
> def itw = new IterableWrapper(delegate: [1,2,3])
> def itwAsList = itw.asList()
> def itwAsTypeList = itw as List
> assert itwAsList == itwAsTypeList
> assert itwAsList[0] == itwAsTypeList[0]
> {code}
> The first assertion passes, but the second fails with:
> {code}
> groovy.lang.MissingMethodException: No signature of method:
> IterableWrapper.get() is applicable for argument types: (java.lang.Integer)
> values: [0]
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)