[
https://issues.apache.org/jira/browse/GROOVY-7912?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15432073#comment-15432073
]
ASF GitHub Bot commented on GROOVY-7912:
----------------------------------------
GitHub user paulk-asert opened a pull request:
https://github.com/apache/groovy/pull/392
GROOVY-7912: MissingPropertyException when referencing a static impor…
…t in a closure's optional parameters
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/paulk-asert/groovy groovy7912
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/groovy/pull/392.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #392
----
commit b3ff90b5a23cdd13736ab026090f6be1e3befe76
Author: paulk <[email protected]>
Date: 2016-08-23T03:26:54Z
GROOVY-7912: MissingPropertyException when referencing a static import in a
closure's optional parameters
----
> MissingPropertyException when referencing a static import in a closure's
> optional parameters
> --------------------------------------------------------------------------------------------
>
> Key: GROOVY-7912
> URL: https://issues.apache.org/jira/browse/GROOVY-7912
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.4.7
> Reporter: M. Justin
> Priority: Minor
>
> A MissingPropertyException is thrown when calling a closure which references
> a statically imported field in the value of an optional parameter for a
> closure. Likewise, a MissingMethodException is thrown when referencing a
> statically imported method in the same manner. This only occurs when calling
> the method without specifying the optional parameter.
> I have confirmed that this issue does not impact methods with optional
> parameters.
> The following code illustrates the issue:
> {code}import static java.util.Collections.EMPTY_LIST
> import static java.util.Collections.emptyList
> Closure closureWithStaticImport = { List list = EMPTY_LIST -> }
> Closure closureWithoutStaticImport = { List list = Collections.EMPTY_LIST -> }
> try {
> // An exception is thrown when the statically imported optional parameter
> is not specified
> closureWithStaticImport()
> } catch (MissingPropertyException e) {
> assert e.message == 'No such property: EMPTY_LIST for class:
> staticImportTest'
> e.printStackTrace()
> }
> // No exception is thrown when the optional parameter is specified
> closureWithStaticImport(EMPTY_LIST)
> // No exception is thrown when the optional parameter is not statically
> imported
> closureWithoutStaticImport()
> void methodWithStaticImport(List list = EMPTY_LIST) {}
> // No exception is thrown when a method's optional parameter uses a static
> import
> methodWithStaticImport()
> Closure closureWithStaticImportMethod = { List list = emptyList() -> }
> try {
> // An exception is thrown when the statically imported optional parameter
> is not specified
> closureWithStaticImportMethod()
> } catch (MissingMethodException e) {
> assert e.message == 'No signature of method: staticImportTest.emptyList()
> is applicable for argument types: () values: []'
> e.printStackTrace()
> }{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)