[ 
https://issues.apache.org/jira/browse/GROOVY-7709?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15071438#comment-15071438
 ] 

Jochen Theodorou commented on GROOVY-7709:
------------------------------------------

The question is what the right behaviour is. In case of {code:Java}inteface Foo 
{ def x(); def y()}
def cl = [x:{1},y:{2}]
def object = cl as Foo
assert object instanceof Foo
assert object.x() == 1
assert object.y() == 2
{code}
We have the map taking care of what method is supposed to be used for a 
specific method. But we do also allow this:
{code:Java}inteface Foo { def x(); def y()}
def cl = {1}
def object = cl as Foo
assert object instanceof Foo
assert object.x() == 1
assert object.y() == 1
{code}
and here the Closure object is taken for everything. So according to that, it 
is not really wrong if the closure reacts to getMetaClass or asBoolean. but 
calling getMetaClass twice... hmm... I can't tell for sure if that is wrong or 
not.

As for the NPE... I have had no time to properly look at this, but could it be 
that it happens, because the returned meta class is null?


> NPE with ConvertedClosure
> -------------------------
>
>                 Key: GROOVY-7709
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7709
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.5
>            Reporter: Jochen Theodorou
>
> {code}
> interface Y extends GroovyObject {}
> def cl = {println 1} as Y
> assert cl instanceof GroovyObject
> if (cl) println "!cl"
> {code}
> the code above will cause the execution of the method getMetaClass in the 
> boolean part of the "if". It looks like this code path now produces a NPE
> {code}
> java.lang.NullPointerException
>       at 
> org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:919)
>       at 
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:902)
>       at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToBoolean(DefaultTypeTransformation.java:185)
>       at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.booleanUnbox(DefaultTypeTransformation.java:74){code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to