<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi Andreas,</p>
<p>great you got it working! Yes, your example triggers the same
problem as the Long constructor. We are investigating still
whether we can solve this easily without causing additional
problems.</p>
<p>Except this problem, is there anything else we can help you with?<br>
</p>
<p>Is this the same application as the one where you reported the
good benchmark results on?</p>
<p>Thanks,<br>
Christian</p>
<p>PS: we also have a slack channel and a #graaljs channel there
<a class="moz-txt-link-freetext" href="https://www.graalvm.org/slack-invitation/">https://www.graalvm.org/slack-invitation/</a><br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">Am 25.03.2020 um 13:33 schrieb Andreas
Mueller:<br>
</div>
<blockquote type="cite"
cite="mid:0102017111af365f-6f3c7b76-2286-48b2-afcb-1e85db989a76-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 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. </div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class="">Andreas</div>
<div class=""><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!NtVsp37tPaKig7jX7vHvKRlXy3rE6ikNZsWJiK8k8AxV9p-nvuwWnlQbQaLuEI3SJgrF$"
class="" moz-do-not-send="true">http://www.swiftmq.com</a><br
class="">
<br class="">
<span><img apple-inline="yes"
id="51304170-527F-4E92-BB56-D5FB44007871"
src="cid:part2.21BC4FEB.94A717E3@oracle.com" class=""></span><br
class="">
</div>
<br class="">
<blockquote type="cite" class="">On 24. Mar 2020, at 17:57,
Christian Wirth <<a
href="mailto:christian.wirth@oracle.com" class=""
moz-do-not-send="true">christian.wirth@oracle.com</a>>
wrote:<br class="">
<br class="">
Hi Andreas,<br class="">
<br class="">
From the error message, I assume you are calling `var Long
= Java.type('java.lang.Long'); new Long('1585059851090')`.<br
class="">
<br class="">
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 class="">
<br class="">
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.<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 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 GraalVM
20.0.0. I’m getting this exception while instantiating
a java.lang.Long object from JS code:<br class="">
<br 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)])<br class="">
<br 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.<br class="">
<br class="">
My ScriptEngine with a mapping String -> long is created
as follows:<br class="">
<br 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="">
}<br 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="">
<br class="">
Any hints?<br class="">
<br class="">
Thanks,<br class="">
Andreas<br class="">
-- <br class="">
Andreas Mueller<br class="">
IIT Software GmbH<br class="">
<a
href="https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!NtVsp37tPaKig7jX7vHvKRlXy3rE6ikNZsWJiK8k8AxV9p-nvuwWnlQbQaLuEI3SJgrF$"
class="" moz-do-not-send="true">http://www.swiftmq.com</a><br
class="">
<br class="">
<span id="cid:part2.D33D6074.F31DE9CC@oracle.com"><swiftmq_logo_positiv.png></span><br
class="">
<br class="">
<br class="">
<br class="">
<div class="">_______________________________________________</div>
<div class="">GraalVM-Users mailing list</div>
<br class="Apple-interchange-newline">
<a class="moz-txt-link-abbreviated" href="mailto:GraalVM-Users@oss.oracle.com">GraalVM-Users@oss.oracle.com</a><br class="">
<a class="moz-txt-link-freetext" href="https://oss.oracle.com/mailman/listinfo/graalvm-users">https://oss.oracle.com/mailman/listinfo/graalvm-users</a><br
class="">
</blockquote>
_______________________________________________<br class="">
GraalVM-Users mailing list<br class="">
<a href="mailto:GraalVM-Users@oss.oracle.com" class=""
moz-do-not-send="true">GraalVM-Users@oss.oracle.com</a><br
class="">
<a class="moz-txt-link-freetext" href="https://oss.oracle.com/mailman/listinfo/graalvm-users">https://oss.oracle.com/mailman/listinfo/graalvm-users</a><br
class="">
</blockquote>
<br class="">
</div>
</blockquote>
</body>
</html>