[graalvm-users] TypeError

Christian Wirth christian.wirth at oracle.com
Tue Mar 24 09:57:35 PDT 2020


Hi Andreas,

 From the error message, I assume you are calling  `var Long = 
Java.type('java.lang.Long'); new Long('1585059851090')`.

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.

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.

Best,
Christian Wirth



Am 24.03.2020 um 15:45 schrieb Andreas Mueller:
> 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
> http://www.swiftmq.com 
> <https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!JAZvy2BRpAt-fq5yTxPdkUbWUdQVGjXcIoEDS73fT4aCdVTUJNELDxHlzbNjh9yULvkOsA$>
>
>
>
> _______________________________________________
> GraalVM-Users mailing list
> GraalVM-Users at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/graalvm-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20200324/f1cdb919/attachment-0001.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/f1cdb919/attachment-0001.png 


More information about the GraalVM-Users mailing list