Remko Popma created GROOVY-8530: ----------------------------------- Summary: map to interface coercion Key: GROOVY-8530 URL: https://issues.apache.org/jira/browse/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: {code} groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.first() is applicable for argument types: () values: [] Possible solutions: print(java.lang.Object), print(java.io.PrintWriter), find(), sort(), is(java.lang.Object), find(groovy.lang.Closure) {code} Here is a minimal class that reproduces the issue: {code} class CoercionTest extends GroovyTestCase { void testCoercion() { def spec = parseFromSpec(MySpec, []) assert spec.foo() == 'firstval' } interface MySpec { String foo(); } public <T> T parseFromSpec(Class<T> optionsClass, args) { def cliOptions = [:] cliOptions['foo'] = 'firstval' cliOptions as T } } {code} This gives: {code} groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.foo() 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(ScriptBytecodeAdapter.java:72) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:48) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) at some.pkg.CoercionTest.testCoercion(CoercionTest.groovy:7) {code} I'm probably doing something wrong, but can't figure out what... Any hints? -- This message was sent by Atlassian JIRA (v7.6.3#76005)