Issue1490

classification
Title: JSR 223 implementation of invokeFunction
Type: behaviour Severity: normal
Components: Versions: 2.5.1
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nriley Nosy List: nriley, rmacaulay
Priority: Keywords:

Created on 2009-10-20.16:49:30 by rmacaulay, last changed 2009-12-09.07:49:09 by nriley.

Messages
msg5248 (view) Author: Robert Macaulay (rmacaulay) Date: 2009-10-20.16:49:29
In org.python.jsr223.PyScriptEngine.invokeFunction(...), the catch
block calls throwInvokeException.

The idea being if you call a top level method that doesn't exist, it
will throw a NoSuchMethodException. However, if the python function
you call(that exists) throws a PyException like this,

Traceback (most recent call last):
  File "<script>", line 19, in inform
AttributeError: 'java.util.HashMap' object has no attribute 'iteritems'

The catch will call throwInvokeException() which will throw a
NoSuchMethod exception with the top level method name as the problem
since the pyException is an AttributeError. In this case, I have just
called an invalid method inside the python script, but it gets masked as
a top level miss.

It seems the invokeFunction already can throw the NoSuchMethod
exception. So the catch block can be changed like this.

--- PyScriptEngine.java.orig    2009-10-15 10:50:28.000000000 -0500
+++ PyScriptEngine.java    2009-10-15 10:51:13.000000000 -0500
@@ -111,7 +111,7 @@
             }
             return
function.__call__(Py.javas2pys(args)).__tojava__(Object.class);
         } catch (PyException pye) {
-            return throwInvokeException(pye, name);
+            throw scriptException(pye);
         }
     }



It looks like the invokeMethod method could suffer from the same
problem, but I'm not sure if the same fix would apply there.
A possible alternative that would cover both cases would be to append
the pye.toString() result inside the NoSuchMethodException constructor
in throwInvokeException()
msg5314 (view) Author: Nicholas Riley (nriley) Date: 2009-11-18.05:04:42
Wow, this was dumb.  Will fix.
msg5364 (view) Author: Nicholas Riley (nriley) Date: 2009-12-09.07:49:08
Fixed. Sorry for the delay.
History
Date User Action Args
2009-12-09 07:49:09nrileysetstatus: open -> closed
resolution: fixed
messages: + msg5364
2009-11-18 05:04:42nrileysetassignee: nriley
messages: + msg5314
nosy: + nriley
2009-10-20 16:49:30rmacaulaycreate