groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remko Popma (JIRA)" <>
Subject [jira] [Created] (GROOVY-8530) map to interface coercion
Date Thu, 05 Apr 2018 08:28:00 GMT
Remko Popma created GROOVY-8530:

             Summary: map to interface coercion
                 Key: GROOVY-8530
             Project: Groovy
          Issue Type: Question
    Affects Versions: 2.5.0-beta-3
            Reporter: Remko Popma

As part of GROOVY-8520, I'm trying to implement the {{CliBuilder.parseFromSpec(Class, String[])}}
method. The implementation of this method populates a Map with data from the command line,
and returns this map, coerced to the specified interface type.

This should work, but the {{CliBuilderTest.testParseFromSpec}} and {{testParseFromInstanceFlagEdgeCases}}
 tests fail with an error:
groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.first()
is applicable for argument types: () values: []
Possible solutions: print(java.lang.Object), print(, find(), sort(), is(java.lang.Object),

Here is a minimal class that reproduces the issue:
class CoercionTest extends GroovyTestCase {

    void testCoercion() {
        def spec = parseFromSpec(MySpec, [])
        assert == 'firstval'

    interface MySpec {
        String foo();

    public <T> T parseFromSpec(Class<T> optionsClass, args) {
        def cliOptions = [:]
        cliOptions['foo'] = 'firstval'
        cliOptions as T

This gives:
groovy.lang.MissingMethodException: No signature of method:
is applicable for argument types: () values: []
Possible solutions: sort(), any(), find(), get(java.lang.Object), get(java.lang.Object), get(java.lang.Object)

 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
 at some.pkg.CoercionTest.testCoercion(CoercionTest.groovy:7)

I'm probably doing something wrong, but can't figure out what... Any hints?

This message was sent by Atlassian JIRA

View raw message