Skip to content

Commit 6f7d4ac

Browse files
committed
Support OpenJDK flavor of Rhino
Previously, our load function would fail on OpenJDK with the cryptic error: sun.org.mozilla.javascript.EvaluatorException: Function importClass must be called with a class; had "[JavaPackage sun.org.mozilla.javascript.internal.Context]" instead. Which was caused by the fact that the wrong fully qualified Context class name was returned: OpenJDK uses sun.org.mozilla.javascript.Context, whereas Oracle Java uses sun.org.mozilla.javascript.internal.Context. This may remain a lurking issue with OpenJDK-8-flavored Nashorn... but I don't have an OpenJDK 8 installation to use for testing at this moment. Hopefully this commit will be enough of a hint to fix similar problems in the future.
1 parent d7aaf0a commit 6f7d4ac

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/org/scijava/plugins/scripting/javascript/JavaScriptScriptLanguage.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,13 @@ private String contextClass(final ScriptEngine engine) {
156156

157157
if (isRhino()) {
158158
if (engineClassName.startsWith("com.sun.")) {
159-
// assume JDK-flavored Rhino script engine
160-
return "sun.org.mozilla.javascript.internal.Context";
159+
if (isOpenJDK()) {
160+
return "sun.org.mozilla.javascript.Context";
161+
}
162+
else {
163+
// assume Oracle version of Java
164+
return "sun.org.mozilla.javascript.internal.Context";
165+
}
161166
}
162167
// assume vanilla Mozilla-flavored Rhino script engine
163168
return "org.mozilla.javascript.Context";

0 commit comments

Comments
 (0)