Troubleshooting java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle in Java build 9+181
Aleksandar Mujadin
aleksandar at mujadin.se
Thu Sep 7 12:10:16 UTC 2017
Hi experts!
It's my first time posting in this forum, I hope I'm not out of line
with my question.
I have a small application that uses Nashorn and JavaScript to extend
the functionality without the need to write/compile Java classes.
My JavaScript file is used to extend an abstract class and it works fine
in Java 8 but when I try to run it with "Java(TM) SE Runtime Environment
(build 9+181)" EA it throws an exception. This is on Windows 10 64-bit.
I'm able to pinpoint it to a specific row in my JavaScript file, if I
comment out that row, then the script loads fine.
The script is available on Github, if I activate row 65 it gives me the
exception:
https://github.com/idsecurity/LDIFTransform/blob/master/doc/transformer-template.js
The specific snippet is here:
function getTransformer(propertiesFile) {
var tc = new TransformerCommon(propertiesFile,
//Modify this function to perform all necessary processing on
the LDIF entry
{ translate: function(entry, firstLineNumber) {
//Use _super_.methodName() to call methods from the
TransformerCommon class.
var _super_ = Java.super(tc);
//Uncomment to remove attributes specified by the
'delete-attribute' property
entry = removeAttributes(entry, _super_.getAttributesToDelete());
return entry;
}});
return tc;
};
The specific row that gives me trouble is:
entry = removeAttributes(entry, _super_.getAttributesToDelete());
That is, if I somehow try to change the "entry" variable it will throw
the exception:
Exception in thread "main" java.lang.invoke.WrongMethodTypeException:
cannot convert MethodHandle(ScriptFunction,Object,Object,Object)int to
(ScriptFunction,Object,Object,Object)Entry
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.se_idsecurity_LDIFTransform_TransformerCommon.translate(Unknown
Source)
at
com.unboundid.ldif.LDIFReader.readEntryInternal(LDIFReader.java:1701)
at com.unboundid.ldif.LDIFReader.readEntry(LDIFReader.java:1277)
at
se.idsecurity.LDIFTransform.LDIFTransform.main(LDIFTransform.java:106)
I have also tried to store the results in a temp variable "x" but as
soon I try to replace entry with x, for example:
entry = x
Or if I try to "return x", I get the above exception.
I'm looking for tips on how I can troubleshoot this further, maybe I my
code is written incorrectly?
The Java 8 version which I'm also testing with and that works is:
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)
Thanks,
Aleksandar
More information about the nashorn-dev
mailing list