groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-7654) Iterable as List and Iterable.asList() have different semantics
Date Tue, 13 Jun 2017 06:19:00 GMT

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

Paul King edited comment on GROOVY-7654 at 6/13/17 6:18 AM:
------------------------------------------------------------

Given what was produced was at least partially unusable, I think it is safe to assume this
is a straight out bug and not some semi-useful behavior that folks might be relying upon -
so I've merged back to 2_4_X.


was (Author: paulk):
Given what was produced was at least partially unusable, I think it is safe to assume this
is a straight out bug and not some semi-useful behavior that folks might be relying upon -
so I've ported back to 2_4_X.

> 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
>            Assignee: Paul King
>             Fix For: 2.4.12
>
>
> 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.4.14#64029)

Mime
View raw message