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

Eric Milles edited comment on GROOVY-10108 at 11/21/22 11:13 PM:
-----------------------------------------------------------------

{code:groovy}
@Immutable(specialNamedArgHandling=false)
class LookupTable {
    Map<Long, String> data
}
{code}
https://github.com/apache/groovy/commit/b8fd0cd22dd417b86050c71d1561c97d14f46c6f


was (Author: emilles):
https://github.com/apache/groovy/commit/b8fd0cd22dd417b86050c71d1561c97d14f46c6f

> Tuple constructor fails for an @Immutable class having a single Map property
> ----------------------------------------------------------------------------
>
>                 Key: GROOVY-10108
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10108
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.0, 2.5.14, 3.0.8
>         Environment: N/A
>            Reporter: Douglas Paul
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.7
>
>
> For an {{@Immutable}} class having a single {{Map}} property, trying to use 
> the generated tuple constructor generally results in an exception being 
> thrown from {{ImmutableASTTransformation.checkPropNames()}}.  This did not 
> happen in Groovy 2.4.
> For example, given a class like this:
> {code:groovy}
> @Immutable
> class LookupTable {
>     Map<Long, String> data
> }
> {code}
> And this usage of that class:
> {code:groovy}
> Map<Long, String> data = [(1L): 'foo', (2L): 'bar']
> new LookupTable(data)
> {code}
> The constructor invocation throws:
> {noformat}
> java.lang.ClassCastException: java.lang.Long cannot be cast to 
> java.lang.String
>       at 
> org.codehaus.groovy.transform.ImmutableASTTransformation.checkPropNames(ImmutableASTTransformation.java:423)
> {noformat}
> The documentation for {{@Immutable}} does mention there are limitations when 
> there is a single property of type {{Map}}, but the wording there doesn't 
> sound like it's talking about the tuple constructor:
> {quote}
> Groovy's normal map-style naming conventions will not be available if the 
> first property has type {{LinkedHashMap}} or if there is a single {{Map}}, 
> {{AbstractMap}} or {{HashMap}} property.
> {quote}
> In fact that wording makes it sound as if it's the map-based constructor that 
> won't be available, when in fact using the map-based constructor does work in 
> this case (and thus seems to be a viable workaround).
> See https://github.com/douglyuckling/groovy-2.5-immutable-with-map-bug for a 
> minimal reproduction of the problem.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to