[Jython-checkins] jython (2.5): #1721 NPE when using JSR 223 (TestCase+Patch) fixed. Thanks kaneiderdaniel!
frank.wierzbicki
jython-checkins at python.org
Tue Mar 20 04:25:39 CET 2012
http://hg.python.org/jython/rev/8a3ae67fdd25
changeset: 6422:8a3ae67fdd25
branch: 2.5
parent: 6420:ea08bca49afb
user: Frank Wierzbicki <fwierzbicki at gmail.com>
date: Mon Mar 19 20:23:49 2012 -0700
summary:
#1721 NPE when using JSR 223 (TestCase+Patch) fixed. Thanks kaneiderdaniel!
files:
src/org/python/jsr223/PyScriptEngine.java | 15 ++++-
tests/java/org/python/jsr223/ScriptEngineIOTest.java | 31 ++++++++++
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/src/org/python/jsr223/PyScriptEngine.java b/src/org/python/jsr223/PyScriptEngine.java
--- a/src/org/python/jsr223/PyScriptEngine.java
+++ b/src/org/python/jsr223/PyScriptEngine.java
@@ -121,7 +121,13 @@
if (function == null) {
throw new NoSuchMethodException(name);
}
- return function.__call__(Py.javas2pys(args)).__tojava__(Object.class);
+ PyObject result;
+ if(args != null) {
+ result = function.__call__(Py.javas2pys(args));
+ } else {
+ result = function.__call__();
+ }
+ return result.__tojava__(Object.class);
} catch (PyException pye) {
throw scriptException(pye);
}
@@ -151,7 +157,12 @@
PyObject pyMethod = thiz.__findattr__(method.getName());
if (pyMethod == null)
throw new NoSuchMethodException(method.getName());
- PyObject result = pyMethod.__call__(Py.javas2pys(args));
+ PyObject result;
+ if(args != null) {
+ result = pyMethod.__call__(Py.javas2pys(args));
+ } else {
+ result = pyMethod.__call__();
+ }
return result.__tojava__(Object.class);
} catch (PyException pye) {
throw scriptException(pye);
diff --git a/tests/java/org/python/jsr223/ScriptEngineIOTest.java b/tests/java/org/python/jsr223/ScriptEngineIOTest.java
--- a/tests/java/org/python/jsr223/ScriptEngineIOTest.java
+++ b/tests/java/org/python/jsr223/ScriptEngineIOTest.java
@@ -1,6 +1,7 @@
package org.python.jsr223;
import javax.script.Bindings;
+import javax.script.Invocable;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
@@ -12,6 +13,7 @@
import java.io.FileReader;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
@@ -116,4 +118,33 @@
assertEquals(61, engine.get("result"));
}
}
+
+ public void testGetInterfaceCharSequence1() throws ScriptException, IOException {
+ ScriptEngineManager manager = new ScriptEngineManager();
+ ScriptEngine engine = manager.getEngineByName("python");
+ Invocable invocableEngine = (Invocable) engine;
+
+ assertNull(engine.eval(
+ "from java.lang import CharSequence\n" +
+ "class MyString(CharSequence):\n" +
+ " def length(self): return 3\n" +
+ " def charAt(self, index): return 'a'\n" +
+ " def subSequence(self, start, end): return \"\"\n" +
+ " def toString(self): return \"aaa\"\n" +
+ "c = MyString()"));
+ CharSequence seq = invocableEngine.getInterface(engine.get("c"), CharSequence.class);
+ assertEquals("aaa", seq.toString());
+ }
+
+ public void testGetInterfaceCharSequence2() throws ScriptException, IOException {
+ ScriptEngineManager manager = new ScriptEngineManager();
+ ScriptEngine pythonEngine = manager.getEngineByName("python");
+ Invocable invocableEngine = (Invocable) pythonEngine;
+
+ assertNull(pythonEngine.eval(
+ "from java.lang import StringBuilder\r\n" +
+ "c = StringBuilder(\"abc\")\r\n"));
+ CharSequence seq = invocableEngine.getInterface(pythonEngine.get("c"), CharSequence.class);
+ assertEquals("abc", seq.toString());
+ }
}
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list