Issue222827
Created on 2000-11-18.19:19:14 by bckfnn, last changed 2000-11-18.22:34:10 by bckfnn.
| Messages | |||
|---|---|---|---|
| msg99 (view) | Author: Finn Bock (bckfnn) | Date: 2000-11-18.19:19:14 | |
Defining a non-static java method with the signature of (PyObject[]
args) will cause the method to be called with the PyJavaInstance as
this instead of the real java object. This cause a exception to be
thrown:
IllegalArgumentException: object is not an instance of declaring
class
IMO the problem occurs because ReflectedArgs.java detects the special
method signature before unwrapping the java object.
--------------------- FILE: test172j.java ---------------------
import org.python.core.*;
public class test172j {
public static void foo(PyObject[] args) {
System.out.println("foo called with " + args.length + "
arguments");
}
public void bar(PyObject[] args) {
System.out.println("bar called with " + args.length + "
arguments");
}
}
--------------------- END ---------------------
--------------------- FILE: test172.py ---------------------
import test172j
test172j.foo(1,2,3,4) # this works
test172j().bar(1,2,3,4) # this does not
--------------------- END ---------------------
d:\java\jpython\test>jpython test172.py
:foo called with 4 arguments
:Traceback (innermost last):
: File "test172.py", line 6, in ?
:java.lang.IllegalArgumentException: object is not an instance of declaring
class
: at java.lang.reflect.Method.invoke(Native Method)
: at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:158)
: at org.python.core.PyMethod.__call__(PyMethod.java:66)
: at org.python.core.PyObject.__call__(PyObject.java:250)
: at org.python.core.PyObject.invoke(PyObject.java:1843)
: at org.python.pycode._pyx0.f$0(test172.py)
: at org.python.pycode._pyx0.call_function(test172.py)
: at org.python.core.PyTableCode.call(PyTableCode.java:155)
: at org.python.core.Py.runCode(Py.java:965)
: at org.python.core.__builtin__.execfile(__builtin__.java:271)
: at org.python.core.__builtin__.execfile(__builtin__.java:275)
: at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:132)
: at org.python.util.jpython.main(jpython.java:124)
:java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: object
is not an instance of declaring class
The patch below is a somewhat brute fix for the problem. Reshuffling
the code is properly better.
d:\java\jpython\test>diff -c
\java\JPython-1.1beta4\org\python\core\ReflectedArg
s.java \java\jpythonCVS.orig\org\python\core\ReflectedArgs.java
*** \java\JPython-1.1beta4\org\python\core\ReflectedArgs.java Fri
Oct 29 18:36
:12 1999
--- \java\jpythonCVS.orig\org\python\core\ReflectedArgs.java Tue
Dec 14 17:47
:22 1999
***************
*** 70,80 ****
--- 70,90 ----
callData.args[0] = pyArgs;
callData.args[1] = keywords;
callData.self = self;
+ if (self != null) {
+ Object tmp = self.__tojava__(declaringClass);
+ if (tmp != Py.NoConversion)
+ callData.self = tmp;
+ }
return true;
} else if (flags == PyArgsCall) { // foo(PyObject[])
callData.setLength(1);
callData.args[0] = pyArgs;
callData.self = self;
+ if (self != null) {
+ Object tmp = self.__tojava__(declaringClass);
+ if (tmp != Py.NoConversion)
+ callData.self = tmp;
+ }
return true;
}
|
|||
| msg100 (view) | Author: Finn Bock (bckfnn) | Date: 2000-11-18.22:34:10 | |
Fixed as suggested. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2000-11-18 19:19:14 | bckfnn | create | |
Supported by Python Software Foundation,
Powered by Roundup