<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi Andreas,</p>
<p>From the error message, I assume you are calling `var Long =
Java.type('java.lang.Long'); new Long('1585059851090')`.<br>
</p>
<p>In that case, as you use targetTypeMapping String=>Long, it
seems we fail to give precedence to the base (unmapped) type,
String in this case. We identify that it is ambigous whether to
call the `Long(String)` or the `Long(long)` (using
targetTypeMapping) constructor, and thus you get the error. <br>
</p>
<p>I would think this is an error on our side. Commenting out the
String->Long targetTypeMapping resolved the problem (and calls
the `Long(String)` constructor). But I'll have to check with our
expert on that matter.</p>
<p>Best,<br>
Christian Wirth<br>
</p>
<p><br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">Am 24.03.2020 um 15:45 schrieb Andreas
Mueller:<br>
</div>
<blockquote type="cite"
cite="mid:010201710d015b0c-5dde35b6-42fb-487b-b34f-970f0c6b2fe5-000000@eu-west-1.amazonses.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Hi,
<div class=""><br class="">
</div>
<div class="">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:</div>
<div class=""><br class="">
</div>
<div class="">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)])</div>
<div class=""><br class="">
</div>
<div class="">The argument I pass is a String and there is a Long
constructor for this so I don’t understand why this is thrown.</div>
<div class=""><br class="">
</div>
<div class="">My ScriptEngine with a mapping String -> long is
created as follows:</div>
<div class=""><br class="">
</div>
<div class="">public class GraalSetup {<br class="">
private static HostAccess getHostAccess() {<br class="">
HostAccess.Builder builder =
HostAccess.newBuilder(HostAccess.ALL);<br class="">
builder.targetTypeMapping(String.class,
Integer.class, null, (v) -> Integer.parseInt(v));<br class="">
builder.targetTypeMapping(String.class,
Long.class, null, (v) -> Long.parseLong(v));<br class="">
builder.targetTypeMapping(String.class,
Double.class, null, (v) -> Double.parseDouble(v));<br
class="">
builder.targetTypeMapping(String.class,
Float.class, null, (v) -> Float.parseFloat(v));<br class="">
builder.targetTypeMapping(Integer.class,
Long.class, null, (v) -> v.longValue());<br class="">
return builder.build();<br class="">
}</div>
<div class=""><br class="">
public static ScriptEngine engine() throws Exception {<br
class="">
return GraalJSScriptEngine.create(null,Context.newBuilder("js").allowAllAccess(true).allowHostAccess(getHostAccess()));<br
class="">
}<br class="">
}<br class="">
</div>
<div class=""><br class="">
</div>
<div class="">Any hints?</div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class="">Andreas<br class="">
<div class="">-- <br class="">
Andreas Mueller<br class="">
IIT Software GmbH<br class="">
<a
href="https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!JAZvy2BRpAt-fq5yTxPdkUbWUdQVGjXcIoEDS73fT4aCdVTUJNELDxHlzbNjh9yULvkOsA$"
class="" moz-do-not-send="true">http://www.swiftmq.com</a><br
class="">
<br class="">
<span><img apple-inline="yes"
id="5B456281-184A-4B70-A649-0CB9CD000B40"
src="cid:part2.D33D6074.F31DE9CC@oracle.com" class=""></span></div>
<br class="">
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
GraalVM-Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:GraalVM-Users@oss.oracle.com">GraalVM-Users@oss.oracle.com</a>
<a class="moz-txt-link-freetext" href="https://oss.oracle.com/mailman/listinfo/graalvm-users">https://oss.oracle.com/mailman/listinfo/graalvm-users</a></pre>
</blockquote>
</body>
</html>