Issue1721

classification
Title: NPE when using JSR 223 (TestCase+Patch)
Type: crash Severity: urgent
Components: Core Versions: 2.5.2rc
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: fwierzbicki Nosy List: fwierzbicki, kaneiderdaniel
Priority: Keywords: patch

Created on 2011-03-21.17:09:52 by kaneiderdaniel, last changed 2012-03-20.03:29:08 by fwierzbicki.

Files
File name Uploaded Description Edit Remove
pyscriptengine.patch kaneiderdaniel, 2011-03-21.17:09:52 Patch-file
Messages
msg6446 (view) Author: dak (kaneiderdaniel) Date: 2011-03-21.17:09:52
The two test cases below exit with a 

java.lang.NullPointerException
	at org.python.core.Py.javas2pys(Py.java:1559)
	at org.python.jsr223.PyScriptEngine$1.invoke(PyScriptEngine.java:154)
	at $Proxy10.toString(Unknown Source)
        .........

	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());
	}
msg6911 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-03-20.03:29:08
Fixed in http://hg.python.org/jython/rev/8a3ae67fdd25 -- fix will show up in 2.5.3. Thanks for the patch kaneiderdaniel!
History
Date User Action Args
2012-03-20 03:29:08fwierzbickisetstatus: open -> closed
resolution: fixed
messages: + msg6911
2012-03-19 23:14:40fwierzbickisetassignee: fwierzbicki
nosy: + fwierzbicki
2011-03-21 17:09:52kaneiderdanielcreate