Message5248

Author rmacaulay
Recipients rmacaulay
Date 2009-10-20.16:49:29
SpamBayes Score 1.6653345e-14
Marked as misclassified No
Message-id <1256057370.93.0.378883431987.issue1490@psf.upfronthosting.co.za>
In-reply-to
Content
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()
History
Date User Action Args
2009-10-20 16:49:31rmacaulaysetrecipients: + rmacaulay
2009-10-20 16:49:30rmacaulaysetmessageid: <1256057370.93.0.378883431987.issue1490@psf.upfronthosting.co.za>
2009-10-20 16:49:30rmacaulaylinkissue1490 messages
2009-10-20 16:49:29rmacaulaycreate