[
https://issues.apache.org/jira/browse/GROOVY-7174?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Daniel Sun resolved GROOVY-7174.
--------------------------------
Resolution: Fixed
> Different behavior in GroovyShell#evaluate vs code right here in groovy script
> ------------------------------------------------------------------------------
>
> Key: GROOVY-7174
> URL: https://issues.apache.org/jira/browse/GROOVY-7174
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 2.3.4, 2.3.7
> Environment: x64 win 8 jdk1.7.0_67
> Reporter: guai
> Assignee: Daniel Sun
> Priority: Major
> Fix For: 7.0.0-alpha-1
>
>
> Same code right here in the script works fine, but in shell.evaluate
> exception raises:
> {code}
> Caught: groovy.lang.GroovyRuntimeException: failed to invoke constructor:
> public HashMapConsumer(HashMap) with arguments: [] reason:
> java.lang.IllegalArgumentException: wrong number of arguments
> groovy.lang.GroovyRuntimeException: failed to invoke constructor: public
> HashMapConsumer(HashMap) with arguments: [] reason:
> java.lang.IllegalArgumentException: wrong number of arguments
> at Script1.run(Script1.groovy:2)
> at name-test.run(name-test.groovy:21)
> {code}
> When I use another name not HashMap for my class it's ok, no exception. Some
> kind of name clash here I think.
> {code}
> public class HashMap<K, V> extends java.util.HashMap<K, V> {
> }
> public class HashMapConsumer {
> HashMap<String, String> map
> public HashMapConsumer(HashMap<String, String> map) {
> this.map = map
> }
> }
> new HashMapConsumer(new HashMap<String, String>() {{
> put("key", "value");
> }}) // ok
> // return
> def shell = new GroovyShell(this.getClass().getClassLoader())
> shell.evaluate('''
> new HashMapConsumer(new HashMap<String, String>() {{
> put("key", "value");
> }})
> ''') // not ok
> {code}
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)