Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PolyglotException when cocatenating String with HashMap #727

Closed
vepo opened this issue Apr 26, 2023 · 2 comments
Closed

PolyglotException when cocatenating String with HashMap #727

vepo opened this issue Apr 26, 2023 · 2 comments

Comments

@vepo
Copy link

vepo commented Apr 26, 2023

I'm trying to migrate a legacy Nashorn + Java 8 project to use GraalVM. As a first step, we are migrating to use GraalVM.js.

When migrating some scripts I found that some of our prints were throwing an exception. This exception happens when we have the following script.

function fn(somePojo, someHashMap) {
    print('' + somePojo.toString()); // It works fine
    print('' + someHashMap.toString()); // It works fine
    print('' + somePojo); // It works fine
    print('' + someHashMap); // Throws org.graalvm.polyglot.PolyglotException
    return 'true';
}

This is a sample code (https://github.com/vepo/graalvm-bug) that for testing. The same exception was thrown when running it with OpenJDK 8 and 20.

[WARNING]
javax.script.ScriptException: org.graalvm.polyglot.PolyglotException: TypeError: (this) has no such function "valueOf"
    at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.toScriptException (GraalJSScriptEngine.java:483)
    at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.invokeFunction (GraalJSScriptEngine.java:558)
    at io.vepo.graalvmjs.GraalVmJsBug.main (GraalVmJsBug.java:52)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:279)
    at java.lang.Thread.run (Thread.java:1623)
Caused by: org.graalvm.polyglot.PolyglotException: TypeError: (this) has no such function "valueOf"
    at <js>.fn (<eval>:5)
    at org.graalvm.polyglot.Value.execute (Value.java:841)
    at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.invokeFunction (GraalJSScriptEngine.java:556)
    at io.vepo.graalvmjs.GraalVmJsBug.main (GraalVmJsBug.java:52)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:279)
    at java.lang.Thread.run (Thread.java:1623)
@vepo vepo changed the title PolyglotException when cocatenating String with map PolyglotException when cocatenating String with HashMap Apr 26, 2023
@iamstolis
Copy link
Member

What version of GraalVM/graaljs do you use? I was able to reproduce this issue in some older GraalVM relase but your test-case works fine in the latest release (GraalVM 22.3.x) or with the latest development version.

@vepo
Copy link
Author

vepo commented Apr 26, 2023

Ow! I was using some old version!

Sorry for that. I should always remember to check with the latest version. 🤦‍♂️

@vepo vepo closed this as completed Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants