<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Hi,<div class=""><br class=""></div><div class="">I got it working without any type mapping. Although I had to change a bunch of scripts.</div><div class=""><br class=""></div><div class="">IMO a problem occurs when you have multiple methods with the same name but different type of parameters. Such as the Long below or Integer.parseInt(..). For example, I have a custom class that has these methods:</div><div class=""><br class=""></div><div class="">myclass.remove(int)</div><div class="">myclass.remove(string)</div><div class=""><br class=""></div><div class="">The caller decides which method is called by either using a string or an int type. This doesn’t seem to work with GraalVM. Once you use type mapping from String to Integer it throws an exception. Expected behavior would be to use the String method when the parameter is a String and use type mapping only if a method with that type isn’t found.&nbsp;</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Andreas</div><div class=""><br class=""><div class="">--&nbsp;<br class="">Andreas Mueller<br class="">IIT Software GmbH<br class=""><a href="https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!PNs0Qd8pB5eyd85XGiLxrtm2zqzuoUFK-KVCcXfD9W1qD52wYLE3aprmEN58TPZiePsw9A$" class="">http://www.swiftmq.com</a><br class=""><br class=""><span><img apple-inline="yes" id="51304170-527F-4E92-BB56-D5FB44007871" src="cid:A0309C4C-D818-48E8-A9CE-B43C74051926@multi.box" class=""></span><br class=""></div><br class=""><blockquote type="cite" class="">On 24. Mar 2020, at 17:57, Christian Wirth &lt;<a href="mailto:christian.wirth@oracle.com" class="">christian.wirth@oracle.com</a>&gt; wrote:<br class=""><br class="">Hi Andreas,<br class=""><br class="">From the error message, I assume you are calling &nbsp;`var Long =&nbsp;Java.type('java.lang.Long'); new Long('1585059851090')`.<br class=""><br class="">In that case, as you use targetTypeMapping String=&gt;Long, it&nbsp;seems we fail to give precedence to the base (unmapped) type,&nbsp;String in this case. We identify that it is ambigous&nbsp;whether to&nbsp;call the `Long(String)` or the `Long(long)` (using&nbsp;targetTypeMapping) constructor, and thus you get the error.&nbsp;<br class=""><br class="">I would think this is an error on our side. Commenting out the&nbsp;String-&gt;Long targetTypeMapping resolved the problem (and calls&nbsp;the `Long(String)` constructor). But I'll have to&nbsp;check with our&nbsp;expert on that matter.<br class=""><br class="">Best,<br class="">Christian Wirth<br class=""><br class=""><br class=""><br class=""><br class=""><br class="">Am 24.03.2020 um 15:45 schrieb Andreas&nbsp;Mueller:<br class=""><blockquote type="cite" cite="mid:010201710d015b0c-5dde35b6-42fb-487b-b34f-970f0c6b2fe5-000000@eu-west-1.amazonses.com" class="">Hi,<br class=""><br class="">I’m testing existing Nashorn JS scripts running on&nbsp;GraalVM 20.0.0. I’m getting this exception while instantiating a&nbsp;java.lang.Long object from JS code:<br class=""><br class="">TypeError: instantiate on JavaClass[java.lang.Long]&nbsp;failed due to: Multiple applicable overloads found for method&nbsp;name java.lang.Long (candidates: [Method[public&nbsp;java.lang.Long(java.lang.String)&nbsp;throws java.lang.NumberFormatException], Method[public&nbsp;java.lang.Long(long)]], arguments: [1585059851090 (String)])<br class=""><br class="">The argument I pass is a String and there is a Long&nbsp;constructor for this so I don’t understand why this is thrown.<br class=""><br class="">My ScriptEngine with a mapping String -&gt; long is&nbsp;created as follows:<br class=""><br class="">public class GraalSetup {<br class="">&nbsp; &nbsp; private static HostAccess getHostAccess() {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; HostAccess.Builder builder =&nbsp;HostAccess.newBuilder(HostAccess.ALL);<br class="">&nbsp; &nbsp; &nbsp; &nbsp; builder.targetTypeMapping(String.class,&nbsp;Integer.class, null, (v) -&gt; Integer.parseInt(v));<br class="">&nbsp; &nbsp; &nbsp; &nbsp; builder.targetTypeMapping(String.class,&nbsp;Long.class, null, (v) -&gt; Long.parseLong(v));<br class="">&nbsp; &nbsp; &nbsp; &nbsp; builder.targetTypeMapping(String.class,&nbsp;Double.class, null, (v) -&gt; Double.parseDouble(v));<br class="">&nbsp; &nbsp; &nbsp; &nbsp; builder.targetTypeMapping(String.class,&nbsp;Float.class, null, (v) -&gt; Float.parseFloat(v));<br class="">&nbsp; &nbsp; &nbsp; &nbsp; builder.targetTypeMapping(Integer.class,&nbsp;Long.class, null, (v) -&gt; v.longValue());<br class="">&nbsp; &nbsp; &nbsp; &nbsp; return builder.build();<br class="">&nbsp; &nbsp; }<br class=""><br class="">&nbsp; &nbsp; public static ScriptEngine engine() throws Exception {<br class="">&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; return GraalJSScriptEngine.create(null,Context.newBuilder("js").allowAllAccess(true).allowHostAccess(getHostAccess()));<br class="">&nbsp; &nbsp; }<br class="">}<br class=""><br class="">Any hints?<br class=""><br class="">Thanks,<br class="">Andreas<br class="">--&nbsp;<br class="">Andreas Mueller<br class="">IIT Software GmbH<br class=""><a href="https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!PNs0Qd8pB5eyd85XGiLxrtm2zqzuoUFK-KVCcXfD9W1qD52wYLE3aprmEN58TPZiePsw9A$" class="">http://www.swiftmq.com</a><br class=""><br class=""><span id="cid:part2.D33D6074.F31DE9CC@oracle.com">&lt;swiftmq_logo_positiv.png&gt;</span><br class=""><br class=""><br class=""><br class=""><div class="">_______________________________________________</div><div class="">GraalVM-Users mailing list</div><br class="Apple-interchange-newline">GraalVM-Users@oss.oracle.com<br class="">https://oss.oracle.com/mailman/listinfo/graalvm-users<br class=""></blockquote>_______________________________________________<br class="">GraalVM-Users mailing list<br class=""><a href="mailto:GraalVM-Users@oss.oracle.com" class="">GraalVM-Users@oss.oracle.com</a><br class="">https://oss.oracle.com/mailman/listinfo/graalvm-users<br class=""></blockquote><br class=""></div></body></html>