Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8069258

ScriptEngine provides an unusable class when passing JavaScript Objects

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • None
    • 8u25
    • core-libs
    • x86
    • linux_ubuntu
    • Verified

    Description

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
      Java HotSpot(TM) Client VM (build 25.25-b02, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Ubunbtu 14.04

      A DESCRIPTION OF THE PROBLEM :
      If a Java method has arguments of type Object, nashorn javaScript calling said java method will try to pass objects as an unusable type.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Arg is (java.util.Map | jdk.nashorn.api.ScriptObjectMirror)
      ACTUAL -
      Arg is jdk.nashorn.internal.scripts.JO4@<hash_code>

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public static class Helper {
           public void doObj(Object arg) {
               System.out.println("Arg is " + arg);
           }
      }

      public static void main(String args[]) throws Exception {
            ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");

            engine.put("helper", new Helper());
            engine.eval("var x = {foo:\"bar\"};\n" +
                        "helper.doObj(x);\n");
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Avoiding parameter types of 'Object' in Java when I know JavaScript will pass js-Objects to Java method.

      Attachments

        Issue Links

          Activity

            People

              sundar Sundararajan Athijegannathan
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: