You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2018/03/17 19:38:00 UTC

[jira] [Commented] (GROOVY-8514) NullPointerException in class MissingMethodException

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

Paul King commented on GROOVY-8514:
-----------------------------------

It's been a while since I've played in that area. I may have forgotten typical usage patterns. I tried a simple example as per below and didn't seem to get the NPE:
{code}
import javax.script.*

def engine = new ScriptEngineManager().getEngineByName("groovy")

def fooImpl = [foo1: { 'Hello' }, foo2: { 'Goodbye' }]
Foo foo = engine.getInterface(fooImpl, Foo)

println foo.foo1()
try {
  println foo.foo2()
} catch(MissingMethodException mme) {
  println mme
}
try {
  println foo.foo3()
} catch(Throwable t) {
  println t.cause
}

interface Foo {
    String foo1()
    String foo3()
}
{code}
Perhaps you can help me create a reproducer.

> NullPointerException in class MissingMethodException
> ----------------------------------------------------
>
>                 Key: GROOVY-8514
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8514
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.14
>            Reporter: Dennis K
>            Priority: Major
>
> The class {{MissingMethodException}} throws an {{NullPointerException}} on {{getMessage()}} if {{arguments}} are null.
> This can happen, if the someone calls {{GroovyScriptEngineImpl.getInterface}} and invokes a method without arguments on that interface. And the method  is not defined in the groovy script.
> The {{InvocationHandler}} calls the method {{invokeImpl}} with {{null}} as arguments, because the interface method has no arguments. If the Method is not defined in the groovy script. A {{MissingMethodException}} is thrown and catched. Than the following {{NoSuchMethodException(var5.getMessage());}} is thrown. But {{getMessage()}} itself throws an NPE due to {{arguments}} is null.
> From the Java Documentation [InvocationHandler|https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/InvocationHandler.html]
> {quote}args - an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
> {quote}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)