You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zeppelin.apache.org by "Gyula Komlossi (Jira)" <ji...@apache.org> on 2019/10/17 10:30:00 UTC
[jira] [Created] (ZEPPELIN-4386) Resource.invokeMethod() doesn't
find the right method to call
Gyula Komlossi created ZEPPELIN-4386:
----------------------------------------
Summary: Resource.invokeMethod() doesn't find the right method to call
Key: ZEPPELIN-4386
URL: https://issues.apache.org/jira/browse/ZEPPELIN-4386
Project: Zeppelin
Issue Type: Bug
Components: zeppelin-interpreter
Affects Versions: 0.9.0
Reporter: Gyula Komlossi
The logic in Resource.invokeMethod() seems to be failing to find the correct method signature if the method is overloaded.
In this part in [Resource.java|[https://github.com/gkomlossi/zeppelin/blob/master/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/Resource.java#L288]]
{code:java}
int pidx = 0;
for (int i = 0; i < paramTypes.length; i++) {
if (pidx == params.length) { // not enough param for this method signature
continue;
} else {
paramValues[i] = params[pidx++];
}
}
if (pidx == params.length) { // param number does not match
found = true;
methodParams = paramValues;
methodTypes = paramTypes;
break;
}
{code}
pidx == params.length will always be true, even if the params.length (incoming param nr) is less than the paramTypes.length (number of parameters required by the method).
The previous logic can easily find such a method (same name but different argument list), because it checks the method name only while it iterates over the array of methods, so it will say found = true, but when it actually invokes the method it will cause an
{code:java}
java.lang.IllegalArgumentExceptionjava.lang.IllegalArgumentException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.zeppelin.resource.Resource.invokeMethod(Resource.java:335) at org.apache.zeppelin.resource.Resource.invokeMethod(Resource.java:313) at org.apache.zeppelin.resource.Resource.invokeMethod(Resource.java:258) at org.apache.zeppelin.resource.Resource.invokeMethod(Resource.java:146){code}
It can be verified by adding this line
assertEquals(2, r.invokeMethod("indexOf", new Object[]{'j'}));
into the test case
ResourceTest#testInvokeMethod_shouldAbleToInvokeMethodWithTypeInference
It will find first and try to call method:
public int java.lang.String.indexOf(java.lang.String,int)
instead of
public int java.lang.String.indexOf(int)
--
This message was sent by Atlassian Jira
(v8.3.4#803005)