[graalvm-users] TypeError

Andreas Mueller am at iit.de
Tue Mar 24 10:06:02 PDT 2020


Hi Christian,

thanks. Yes, that would solve this but would cause another one when I call a method that is unique. For that case I need this String->Long conversion. Nashorn is very relaxed on this matter…

Problem is really to migrate a huge number of JS scripts that you can’t touch because they run on customer site. So the only option is to make GraalVM fully compatible.

The best would be to have a predefined Nashorn mapping that is automatically set once you get into Nashorn compatibility mode.

Thanks,
Andreas

-- 
Andreas Mueller
IIT Software GmbH
https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!KwXcC9xGHGwJdjX6eGvunWgsx0m8Ju27PKChsklscVhiFS4rfxl2TQqee194Q-VRp17U1Q$  <https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!KwXcC9xGHGwJdjX6eGvunWgsx0m8Ju27PKChsklscVhiFS4rfxl2TQqee194Q-VRp17U1Q$ > 



On 24. Mar 2020, at 17:57, Christian Wirth <christian.wirth at oracle.com <mailto:christian.wirth at oracle.com> > wrote:

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
https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!KwXcC9xGHGwJdjX6eGvunWgsx0m8Ju27PKChsklscVhiFS4rfxl2TQqee194Q-VRp17U1Q$  <https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!KwXcC9xGHGwJdjX6eGvunWgsx0m8Ju27PKChsklscVhiFS4rfxl2TQqee194Q-VRp17U1Q$ > 

<swiftmq_logo_positiv.png>



_______________________________________________
GraalVM-Users mailing list

GraalVM-Users at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/graalvm-users
_______________________________________________
GraalVM-Users mailing list
GraalVM-Users at oss.oracle.com <mailto: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/42dde169/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/42dde169/attachment-0001.png 


More information about the GraalVM-Users mailing list