[graalvm-users] TypeError
Andreas Mueller
am at iit.de
Tue Mar 24 07:45:24 PDT 2020
Hi,
I’m testing existing Nashorn JS scripts running on GraalVM 20.0.0. I’m getting this exception while instantiating a java.lang.Long object from JS code:
TypeError: instantiate on JavaClass[java.lang.Long] failed due to: Multiple applicable overloads found for method name java.lang.Long (candidates: [Method[public java.lang.Long(java.lang.String) throws java.lang.NumberFormatException], Method[public java.lang.Long(long)]], arguments: [1585059851090 (String)])
The argument I pass is a String and there is a Long constructor for this so I don’t understand why this is thrown.
My ScriptEngine with a mapping String -> long is created as follows:
public class GraalSetup {
private static HostAccess getHostAccess() {
HostAccess.Builder builder = HostAccess.newBuilder(HostAccess.ALL);
builder.targetTypeMapping(String.class, Integer.class, null, (v) -> Integer.parseInt(v));
builder.targetTypeMapping(String.class, Long.class, null, (v) -> Long.parseLong(v));
builder.targetTypeMapping(String.class, Double.class, null, (v) -> Double.parseDouble(v));
builder.targetTypeMapping(String.class, Float.class, null, (v) -> Float.parseFloat(v));
builder.targetTypeMapping(Integer.class, Long.class, null, (v) -> v.longValue());
return builder.build();
}
public static ScriptEngine engine() throws Exception {
return GraalJSScriptEngine.create(null,Context.newBuilder("js").allowAllAccess(true).allowHostAccess(getHostAccess()));
}
}
Any hints?
Thanks,
Andreas
--
Andreas Mueller
IIT Software GmbH
https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!JAZvy2BRpAt-fq5yTxPdkUbWUdQVGjXcIoEDS73fT4aCdVTUJNELDxHlzbNjh9yULvkOsA$ <https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!JAZvy2BRpAt-fq5yTxPdkUbWUdQVGjXcIoEDS73fT4aCdVTUJNELDxHlzbNjh9yULvkOsA$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20200324/609be962/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swiftmq_logo_positiv.png
Type: image/png
Size: 10241 bytes
Desc: not available
Url : http://oss.oracle.com/pipermail/graalvm-users/attachments/20200324/609be962/attachment.png
More information about the GraalVM-Users
mailing list