You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/10/29 21:26:00 UTC

[jira] [Assigned] (GROOVY-7236) Cannot create a closure referencing a method of anonymous inner class.

     [ https://issues.apache.org/jira/browse/GROOVY-7236?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles reassigned GROOVY-7236:
-----------------------------------

    Assignee: Eric Milles

> Cannot create a closure referencing a method of anonymous inner class.
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-7236
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7236
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.3.7, 2.4.0-rc-1
>         Environment: Ubuntu linux 
>            Reporter: Vassil Mihaylov
>            Assignee: Eric Milles
>            Priority: Major
>         Attachments: HTTPTest.groovy
>
>
> When running this code:
> {code}
>         http.setParserRegistry(new ParserRegistry() {
>             @Override
>             protected Map buildDefaultParserMap() {
>                 def parsers = super.buildDefaultParserMap();
>                 parsers.put("application/hal+json", new MethodClosure(this, "parseJSON"))
>                 return parsers
>             }
>         });
> {code}
> I get:
> {code}
> java.lang.IllegalArgumentException: object is not an instance of declaring class
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:606)
> 	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
> 	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
> 	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)
> 	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1074)
> 	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
> 	at groovy.lang.Closure.call(Closure.java:423)
> 	at groovy.lang.Closure.call(Closure.java:439)
> 	at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:551)
> 	at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:480)
> {code}
> However if I create a separate class like this: 
> {code}
> class MyParserRegistry extends ParserRegistry {
>     @Override
>     protected Map<String, Closure> buildDefaultParserMap() {
>         Map parsers = super.buildDefaultParserMap();
>         parsers.put("application/hal+json", new MethodClosure(this, "parseJSON"));
>         return parsers;
>     }
> }
> {code}
> and then invoke:
> {code}
> http.setParserRegistry(new MyParserRegistry())
> {code}
> everything works fine.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)