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

Paul King resolved GROOVY-8416.
-------------------------------
       Resolution: Fixed
    Fix Version/s: 2.5.0-beta-3

This was fixed as part of recent changes for 2.5.0-beta-3 but I forgot to close 
this issue before release. Commit: e5e8fe1af3

It means in your example you can now do:
{code}
def p3 = new Point(new TreeMap(coordinates))
assert p3.x == 1
{code}


> Map-based constructor generated by @Immutable works only with HashMap
> ---------------------------------------------------------------------
>
>                 Key: GROOVY-8416
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8416
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.13
>            Reporter: Andreas Mayer
>            Assignee: Paul King
>            Priority: Major
>             Fix For: 2.5.0-beta-3
>
>
> If you call the map-based constructor of an {{@Immutable}} class with a 
> non-{{HashMap}}, it will try to set the properties via setters, which causes 
> a {{ReadOnlyPropertyException}}. Somehow it works with {{HashMap}} or 
> subclasses like {{LinkedHashMap}}. Why?
> {code}
> import groovy.transform.Immutable
> @Immutable
> class Point {
>       int x
>       int y
> }
> def coordinates = [x: 1, y: 2]
> assert coordinates instanceof LinkedHashMap
> def p1 = new Point(coordinates)
> assert p1.x == 1
> def p2 = new Point(new HashMap(coordinates))
> assert p2.x == 1
> try {
>       new Point(new TreeMap(coordinates))
> } catch (e) {
>       assert e instanceof ReadOnlyPropertyException
> }
> try {
>       new Point(coordinates.asImmutable())
> } catch (e) {
>       assert e instanceof ReadOnlyPropertyException
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to