[
https://issues.apache.org/jira/browse/GROOVY-9661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17168899#comment-17168899
]
Paul King commented on GROOVY-9661:
-----------------------------------
Turns out there's not as obvious a fix as you might first think:
* while there was no Groovy syntax pre-Parrot which used the initializer
expressions, they could be added programmatically as is done in
MarkupBuilderCodeTransformer, and such code would be looking for null for the
sizeExpression currently if an initializer is used, so changing it could break
code
* the plural "getExpressions" vs non-plural "getSizeExpression" inconsistency
is also messy to change - though we could introduce aliases and deprecate the
original - in some sense either could work - it is in fact an "initializer"
expression (singular) consisting of the list of individual expressions (plural)
For now I have:
* added a {{hasInitializer()}} method so that whether a null or empty list is
used for sizeExpression can remain a hidden internal detail
* clarified the javadoc comments to make the naming inconsistency a little
easier to comprehend
> Since Groovy 3 ArrayExpression#sizeExpression can suddenly return null
> ----------------------------------------------------------------------
>
> Key: GROOVY-9661
> URL: https://issues.apache.org/jira/browse/GROOVY-9661
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 3.0.5
> Reporter: Björn Kautler
> Priority: Major
>
> Before Groovy 3, {{ArrayExpression#sizeExpression}} never was {{null}},
> because you could only write {{new Object[0][1]}}, but {{new Object[] \{ 1, 2
> }}} was not valid syntax.
> Now with Groovy 3 both syntaxes are valid.
> In the former case you get for {{expressions}} an empty list and for
> {{sizeExpression}} a list with the two size expressions.
> In the latter case you get for {{expressions}} a list with the two member
> expressions and for {{sizeExpression}} you get {{null}}.
> This is somewhat unexpected and inconsistent.
> Some code (Spock currently does unless
> [https://github.com/spockframework/spock/pull/1203/files] gets merged) might
> assume {{sizeExpression}} is always non-{{null}} as it always was.
> I asked Paul and he said this should probably be fixed on Groovy side to also
> provide an empty list here, so here is the according issue. :)
--
This message was sent by Atlassian Jira
(v8.3.4#803005)