← Back to team overview

openjdk team mailing list archive

[Bug 1553654] [NEW] In JavaScript engine, some String operations produce ConsString instead, type errors at runtime

 

Public bug reported:

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

** Affects: openjdk-7 (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of OpenJDK,
which is subscribed to openjdk-7 in Ubuntu.
https://bugs.launchpad.net/bugs/1553654

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

Status in openjdk-7 package in Ubuntu:
  New

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 manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/openjdk-7/+bug/1553654/+subscriptions