Skip to content

Commit c8e8fde

Browse files
committed
Wrap the stock Jython JSR-223 ScriptEngine
We wanted to do this before, but 2.5.3 has a bug which did not occur with the SciJava ScriptEngine implementation, so we stuck with that. But now that we switched to Jython 2.7.0, it is no longer an issue.
1 parent e1b6a61 commit c8e8fde

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

src/main/java/org/scijava/plugins/scripting/jython/JythonScriptLanguage.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,6 @@ public JythonScriptLanguage() {
6262
super("jython");
6363
}
6464

65-
@Override
66-
public ScriptEngine getScriptEngine() {
67-
// NB: recursive priorities can only be resolved via inter-service
68-
// dependencies. There is no way to make the ScriptService
69-
// depend on the JythonService because of the hierarchy
70-
// of components. So we have to get the JythonService indirectly.
71-
return context.service(JythonService.class).getScriptEngine();
72-
}
73-
7465
@Override
7566
public Object decode(final Object object) {
7667
if (object instanceof PyNone) return null;

src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.junit.After;
4747
import org.junit.Before;
4848
import org.junit.Test;
49+
import org.python.jsr223.PyScriptEngine;
4950
import org.scijava.Context;
5051
import org.scijava.script.ScriptLanguage;
5152
import org.scijava.script.ScriptModule;
@@ -87,7 +88,7 @@ public void testBasic() throws InterruptedException, ExecutionException,
8788
public void testLocals() throws ScriptException {
8889
final ScriptLanguage language = scriptService.getLanguageByExtension("py");
8990
final ScriptEngine engine = language.getScriptEngine();
90-
assertEquals(JythonScriptEngine.class, engine.getClass());
91+
assertEquals(PyScriptEngine.class, engine.getClass());
9192
engine.put("hello", 17);
9293
assertEquals(17, language.decode(engine.eval("hello")));
9394
assertEquals(17, language.decode(engine.get("hello")));
@@ -117,20 +118,20 @@ public void testParameters() throws InterruptedException, ExecutionException,
117118
* Tests that variables assigned a primitive long value have the expected
118119
* type.
119120
* <p>
120-
* There is a crazy bug in {@link org.python.jsr223.PyScriptEngine}, which
121-
* results in variables assigned a long primitive to somehow end up as (or
121+
* There was a crazy bug in {@link PyScriptEngine} version 2.5.3, which
122+
* resulted in variables assigned a long primitive to somehow end up as (or
122123
* appearing to end up as) {@link java.math.BigInteger} instances instead. See
123124
* <a href=
124125
* "http://sourceforge.net/p/jython/mailman/jython-users/thread/54370FE9.5010603%40farowl.co.uk/"
125126
* >this thread on the jython-users mailing list</a> for discussion.
126127
* </p>
127128
* <p>
128-
* This test ensures that that specific problem gets flagged if it occurs. As
129-
* long as we keep using our own Jython {@code ScriptEngine} implementation
130-
* (i.e.: {@link org.scijava.plugins.scripting.jython.JythonScriptEngine}),
131-
* the problem does not occur. But if we switch to the stock JSR-223 Jython
132-
* {@code ScriptEngine} (i.e.: {@link org.python.jsr223.PyScriptEngine}), the
133-
* problem manifests. See {@link JythonScriptLanguage#getScriptEngine()}.
129+
* This test ensures that that specific problem gets flagged if it recurs.
130+
* Previously, to avoid it, we used our own Jython {@code ScriptEngine}
131+
* implementation
132+
* ({@code org.scijava.plugins.scripting.jython.JythonScriptEngine}). But
133+
* since Jython 2.7.0, the stock JSR-223 Jython {@code ScriptEngine} (i.e.:
134+
* {@link org.python.jsr223.PyScriptEngine}) no longer has this issue.
134135
* </p>
135136
*/
136137
@Test

0 commit comments

Comments
 (0)