You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2015/10/10 13:40:05 UTC

[jira] [Commented] (GROOVY-7624) Collection asImmutable() methods aren't immutable

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

Paul King commented on GROOVY-7624:
-----------------------------------

Yes, the easiest things is probably calling {{clone()}} on the Collection (and Set, Map etc.) instance before passing to {{unmodifiable}}. Of course Collection is not Cloneable but most of the implementations are, so it's a little messy. We already have a standard way of implementing this though, e.g. the code produced by the @AutoClone AST transform. We could do something similar and just make sure it still makes sense when used in conjunction with @TypeChecked/@CompileStatic.

> Collection asImmutable() methods aren't immutable
> -------------------------------------------------
>
>                 Key: GROOVY-7624
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7624
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 2.4.5
>            Reporter: Christopher Smith
>            Assignee: Guillaume Laforge
>            Priority: Minor
>
> The contract for the Collection {{asImmutable()}} methods specify that the returned collection is immutable, but in fact the collection is merely read-only; it uses {{Collections.unmodifiable*()}}, which wraps an underlying collection that is still mutable.
> These methods should return actual immutable collections, either using Collections unmodifiables with copies of the underlying collections or using an actual immutable backing implementation, a la Guava.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)