From: <nr...@us...> - 2009-12-09 07:49:02
|
Revision: 6956 http://jython.svn.sourceforge.net/jython/?rev=6956&view=rev Author: nriley Date: 2009-12-09 07:48:45 +0000 (Wed, 09 Dec 2009) Log Message: ----------- Fix incorrect conversion of AttributeError to NoSuchMethodException (#1490) in JSR 223 interface. Thanks to Robert Macaulay. Modified Paths: -------------- trunk/jython/src/org/python/jsr223/PyScriptEngine.java Modified: trunk/jython/src/org/python/jsr223/PyScriptEngine.java =================================================================== --- trunk/jython/src/org/python/jsr223/PyScriptEngine.java 2009-12-08 03:07:15 UTC (rev 6955) +++ trunk/jython/src/org/python/jsr223/PyScriptEngine.java 2009-12-09 07:48:45 UTC (rev 6956) @@ -96,9 +96,13 @@ if (!(thiz instanceof PyObject)) { thiz = Py.java2py(thiz); } - return ((PyObject) thiz).invoke(name, Py.javas2pys(args)).__tojava__(Object.class); + PyObject method = ((PyObject) thiz).__findattr__(name); + if (method == null) { + throw new NoSuchMethodException(name); + } + return method.__call__(Py.javas2pys(args)).__tojava__(Object.class); } catch (PyException pye) { - return throwInvokeException(pye, name); + throw scriptException(pye); } } @@ -111,7 +115,7 @@ } return function.__call__(Py.javas2pys(args)).__tojava__(Object.class); } catch (PyException pye) { - return throwInvokeException(pye, name); + throw scriptException(pye); } } @@ -134,24 +138,19 @@ new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { - PyObject result = thiz.invoke(method.getName(), Py.javas2pys(args)); + PyObject pyMethod = thiz.__findattr__(method.getName()); + if (pyMethod == null) + throw new NoSuchMethodException(method.getName()); + PyObject result = pyMethod.__call__(Py.javas2pys(args)); return result.__tojava__(Object.class); } catch (PyException pye) { - return throwInvokeException(pye, method.getName()); + throw scriptException(pye); } } }); return proxy; } - private static Object throwInvokeException(PyException pye, String methodName) - throws ScriptException, NoSuchMethodException { - if (pye.match(Py.AttributeError)) { - throw new NoSuchMethodException(methodName); - } - throw scriptException(pye); - } - private static ScriptException scriptException(PyException pye) { ScriptException se = null; try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |