In JavaScript engine, some String operations produce ConsString instead, type errors at runtime

Bug #1553654 reported by Peter Brewer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
openjdk-7 (Ubuntu)
New
Undecided
Unassigned

Bug Description

I have a small task that's done in Java's javax.script engine for JavaScript, which I understand was based on Rhino in Java SE 6 and 7, swapped out for Nashorn in Java SE 8. The code fails to run in openjdk-6 (38) and openjdk-7(95) - both i386 and amd64- but *only* in Ubuntu. A colleague has tested the exact same releases of Java in Redhat without the error. The code, however, works fine in openjdk-8 in both Ubuntu and Redhat.

The main issue seems to be that the + operator between two strings no longer produces a string result, it produces a sun.org.mozilla.javascript.ConsString instead. That doesn't behave as a regular String (it lacks a replace method, passing it as a parameter to a Java method expecting String produces method not found because the signature is wrong, etc.) If I edit and change every string expression s1 + s2 to be String(s1 + s2) then I have a usable string again.

Here is some code to reproduce the error:
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class jstest {
  public static void main(String[] args) throws Exception {
    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine testEngine =
      mgr.getEngineByMimeType( "application/javascript");

    String testScript =
" var key = 'something';\n" +
" var tpr = 'echo';\n" +
" var pb = new java.lang.ProcessBuilder(tpr, '--', '--'+key);\n" +
" pb.start().waitFor();\n";

    System.out.println(testEngine.eval(testScript)); // success prints 0
  }
}

Running in Ubuntu gives this error:
javax.script.ScriptException: sun.org.mozilla.javascript.EvaluatorException: Java constructor for "java.lang.ProcessBuilder" with arguments "string,string,sun.org.mozilla.javascript.ConsString" not found.

Any ideas what's going wrong and why only in Ubuntu?

Version details:
Ubuntu 14.04.4 LTS
openjdk-6-jdk - 6b38-1.13.10-0ubuntu0.14.04.1
openjdk-7-jdk - 7u95-2.6.4-0ubuntu0.14.04.1

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.