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

Nashorn bug in Invocable.getInterface

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • CPU:
      x86_64
    • OS:
      os_x

      Description

      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 :
      Darwin xx 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      a = engine.getInterface({
              size: function () {
                  print("size");
                  return 0;
              },
              isEmpty: function () {
                  print("isEmpty");
                  return this.size() > 0;
              },
              contains: function (o) {
                  print("contains");
                  return false;
              },
              iterator: function () {
                  print("iterator");
                  return null;
              },
              toArray: function (arry) {
                  print("toArray");
                  return Java.to([], "java.lang.Object[]");
              },
              add: function (e) {
                  print("add");
                  return false;
              },
              remove: function (e) {
                  print("remove");
                  return false;
              },
              containsAll: function (e) {
                  print("containsAll");
                  return false;
              },
              addAll: function (e) {
                  print("addAll");
                  return false;
              },
              retainAll: function (e) {
                  print("retainAll");
                  return false;
              },
              removeAll: function (e) {
                  print("removeAll");
                  return false;
              },
              clear: function () {
                  print("clear");
              },
              equals: function (e) {
                  print("equals");
                  return false;
              },
              hashCode: function () {
                  print("hashCode");
                  return 0;
              }
          }, java.util.Set.class);


      a.toArray(); // will be a exception

      REGRESSION. Last worked in version 8u144

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_144"
      Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      jrunscript

      a = engine.getInterface({ size: function () { print("size"); return 0; }, isEmpty: function () { print("isEmpty"); return this.size() > 0; }, contains: function (o) { print("contains"); return false; }, iterator: function () { print("iterator"); return null; }, toArray: function (arry) { print("toArray"); return Java.to([], "java.lang.Object[]"); }, add: function (e) { print("add"); return false; }, remove: function (e) { print("remove"); return false; }, containsAll: function (e) { print("containsAll"); return false; }, addAll: function (e) { print("addAll"); return false; }, retainAll: function (e) { print("retainAll"); return false; }, removeAll: function (e) { print("removeAll"); return false; }, clear: function () { print("clear"); }, equals: function (e) { print("equals"); return false; }, hashCode: function () { print("hashCode"); return 0; } }, java.util.Set.class);

      a.toArray();


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      toArray
      [Ljava.lang.Object;@xxxxxxxx
      ACTUAL -
      java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(ScriptFunction,Object,Object)int to (ScriptFunction,Object,Object)Object[]
      at java.base/java.lang.invoke.MethodHandle.asTypeUncached(MethodHandle.java:786)
      at java.base/java.lang.invoke.MethodHandle.asType(MethodHandle.java:772)
      at jdk.dynalink/jdk.dynalink.TypeConverterFactory.asType(TypeConverterFactory.java:280)
      at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.asType(LinkerServicesImpl.java:131)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.changeReturnType(CompiledFunction.java:731)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.createInvoker(CompiledFunction.java:715)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.access$200(CompiledFunction.java:62)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction$2.get(CompiledFunction.java:677)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction$2.get(CompiledFunction.java:674)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.getValidOptimisticInvocation(CompiledFunction.java:620)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.createFunctionInvocation(CompiledFunction.java:674)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.findCallMethod(ScriptFunction.java:949)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptObject.lookup(ScriptObject.java:1874)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:104)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:96)
      at jdk.dynalink/jdk.dynalink.linker.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:184)
      at jdk.dynalink/jdk.dynalink.linker.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:132)
      at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.lambda$getGuardedInvocation$0(LinkerServicesImpl.java:160)
      at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getWithLookupInternal(LinkerServicesImpl.java:191)
      at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:158)
      at jdk.dynalink/jdk.dynalink.DynamicLinker.relink(DynamicLinker.java:265)
      at jdk.nashorn.javaadapters.java_util_Set.toArray(Unknown Source)
      at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$43$\^STDIN\_/1276544608.:program(<STDIN>:1)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:652)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:517)
      at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:448)
      at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:405)
      at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:401)
      at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:154)
      at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
      at java.scripting/com.sun.tools.script.shell.Main.evaluateString(Main.java:298)
      at java.scripting/com.sun.tools.script.shell.Main.processSource(Main.java:267)
      at java.scripting/com.sun.tools.script.shell.Main.access$100(Main.java:37)
      at java.scripting/com.sun.tools.script.shell.Main$1.run(Main.java:183)
      at java.scripting/com.sun.tools.script.shell.Main.main(Main.java:48)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(ScriptFunction,Object,Object)int to (ScriptFunction,Object,Object)Object[]
      at java.base/java.lang.invoke.MethodHandle.asTypeUncached(MethodHandle.java:786)
      at java.base/java.lang.invoke.MethodHandle.asType(MethodHandle.java:772)
      at jdk.dynalink/jdk.dynalink.TypeConverterFactory.asType(TypeConverterFactory.java:280)
      at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.asType(LinkerServicesImpl.java:131)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.changeReturnType(CompiledFunction.java:731)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.createInvoker(CompiledFunction.java:715)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.access$200(CompiledFunction.java:62)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction$2.get(CompiledFunction.java:677)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction$2.get(CompiledFunction.java:674)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.getValidOptimisticInvocation(CompiledFunction.java:620)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.CompiledFunction.createFunctionInvocation(CompiledFunction.java:674)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.findCallMethod(ScriptFunction.java:949)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptObject.lookup(ScriptObject.java:1874)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:104)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:96)
      at jdk.dynalink/jdk.dynalink.linker.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:184)
      at jdk.dynalink/jdk.dynalink.linker.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:132)
      at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.lambda$getGuardedInvocation$0(LinkerServicesImpl.java:160)
      at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getWithLookupInternal(LinkerServicesImpl.java:191)
      at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:158)
      at jdk.dynalink/jdk.dynalink.DynamicLinker.relink(DynamicLinker.java:265)
      at jdk.nashorn.javaadapters.java_util_Set.toArray(Unknown Source)
      at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$43$\^STDIN\_/1276544608.:program(<STDIN>:1)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:652)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
      at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:517)
      at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:448)
      at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:405)
      at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:401)
      at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:154)
      at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
      at java.scripting/com.sun.tools.script.shell.Main.evaluateString(Main.java:298)
      at java.scripting/com.sun.tools.script.shell.Main.processSource(Main.java:267)
      at java.scripting/com.sun.tools.script.shell.Main.access$100(Main.java:37)
      at java.scripting/com.sun.tools.script.shell.Main$1.run(Main.java:183)
      at java.scripting/com.sun.tools.script.shell.Main.main(Main.java:48)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      jrunscript

      a = engine.getInterface({ size: function () { print("size"); return 0; }, isEmpty: function () { print("isEmpty"); return this.size() > 0; }, contains: function (o) { print("contains"); return false; }, iterator: function () { print("iterator"); return null; }, toArray: function (arry) { print("toArray"); return Java.to([], "java.lang.Object[]"); }, add: function (e) { print("add"); return false; }, remove: function (e) { print("remove"); return false; }, containsAll: function (e) { print("containsAll"); return false; }, addAll: function (e) { print("addAll"); return false; }, retainAll: function (e) { print("retainAll"); return false; }, removeAll: function (e) { print("removeAll"); return false; }, clear: function () { print("clear"); }, equals: function (e) { print("equals"); return false; }, hashCode: function () { print("hashCode"); return 0; } }, java.util.Set.class);

      a.toArray();
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                hannesw Hannes Wallnoefer
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: