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

jdk.nashorn.api.scripting.ScriptUtils.wrap is useless in JDK 9

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "9"
      Java(TM) SE Runtime Environment (build 9+181)
      Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux xxxxx 2.6.39-400.297.3.el6uek.x86_64 #1 SMP Fri Jun 30 10:09:45 PDT 2017 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      According to the OpenJDK source repository, the jdk.nashorn.api.scripting.ScriptUtils.wrap method is:

        public static ScriptObjectMirror wrap(final Object obj) {
              if (obj instanceof ScriptObjectMirror) {
                  return (ScriptObjectMirror)obj;
              }

              if (obj instanceof ScriptObject) {
                  final ScriptObject sobj = (ScriptObject)obj;
                  return (ScriptObjectMirror) ScriptObjectMirror.wrap(sobj, Context.getGlobal());
              }

              throw new IllegalArgumentException();
          }

      If the argument is not a ScriptObjectMirrot or a jdk.nashorn.internal.runtime.ScriptObject, an IllegalArgumentException is thrown. However in JDK9 jdk.nashorn.internal.runtime.ScriptObject is an unexported class, so calling code cannot check the type of the argument before calling wrap.



      REGRESSION. Last worked in version 8u144

      ADDITIONAL REGRESSION INFORMATION:
      In Java 8 you could check the argument type before calling wrap by

      if (obj instanceof jdk.nashorn.internal.runtime.ScriptObject) { ...

      This code will not compile in JDK 9 and fails at runtime if code compiled with JDK 1.8 is used.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      jdk.nashorn.api.scripting.ScriptUtils.wrap("this will throw an exception")

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should not have to catch and ignore IllegalArgumentException
      ACTUAL -
      IllegalArgumentException is thrown

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.IllegalArgumentException
      at jdk.scripting.nashorn/jdk.nashorn.api.scripting.ScriptUtils.wrap(ScriptUtils.java:105)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      jdk.nashorn.api.scripting.ScriptUtils.wrap("this will throw an exception")
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved: