0

I tried to extend scaffolded quarkus demo, https://code.quarkus.io/, with polyglot code for GraalVM:

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
    String out = "From JS:";
    try (Context context = Context.create()) {
        Value function = context.eval("js", "x => x+1");
        assert function.canExecute();
        int x = function.execute(41).asInt();
        out=out+x;
        System.out.println(out);
    }
    return "hello";
}

I added dependencies to pom.xml as suggested here [https://stackoverflow.com/questions/54384499/illegalstateexception-no-language-and-polyglot-implementation-was-found-on-the]

<dependency>
  <groupId>org.graalvm.js</groupId>
  <artifactId>js</artifactId>
  <version>20.1.0</version>
</dependency>
<dependency>
  <groupId>org.graalvm.js</groupId>
  <artifactId>js-scriptengine</artifactId>
  <version>20.1.0</version>
</dependency>
<dependency>
  <groupId>org.graalvm.truffle</groupId>
  <artifactId>truffle-api</artifactId>
  <version>20.1.0</version>
</dependency>

But when I run on cmd line

./mvnw clean package

Test fails with exception, which I do not understand.

2020-06-22 19:26:56,328 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] 
(executor-thread-1) HTTP Request to /hello failed, error id: 996b0479-d836-47a5-bbcb-67bd876f9277-1: org.jboss.resteasy.spi.UnhandledException: 
java.lang.IllegalAccessError: superclass access check failed: 
class com.oracle.truffle.polyglot.PolyglotImpl (in unnamed module @0x7bf61ba2) cannot access class org.graalvm.polyglot.impl.AbstractPolyglotImpl (in module org.graalvm.sdk) 
because module org.graalvm.sdk does not export org.graalvm.polyglot.impl to unnamed module @0x7bf61ba2

UPDATE:

It looks like regression in quarkus, https://github.com/quarkusio/quarkus/issues/10226. App test is passing when used with quarkus 1.2.1 (instead of 1.5.2). enter image description here

  • Repo https://github.com/miloslavskacel/polyglotcode-with-quarkus.git can be used to reproduce. –  Jun 22 '20 at 17:46

2 Answers2

0

Look into the mvn dependency:tree -- it turns out that org.graalvm.js:js:20.1.0 depends on org.graalvm.sdk:graal-sdk:19.3.1. I'd personally call that GraalVM JS bug.

If you add an explicit dependency on org.graalvm.sdk:graal-sdk:20.1.0, it should work.

(At least it did for me, but I was getting a different error than you, so not sure.)

EDIT: as I was warned about in the comment, it is not true that org.graalvm.js:js:20.1.0 depends on org.graalvm.sdk:graal-sdk:19.3.1. Instead, there must be something else that forces graal-sdk to 19.3.1, perhaps something from Quarkus. Explicitly managing it to 20.1.0 should still help.

Ladicek
  • 5,970
  • 17
  • 20
  • I don't think this is correct. According to https://search.maven.org/artifact/org.graalvm.js/js/20.1.0/jar the Graal.js JAR has this static dependency on `org.graalvm.sdk:graal-sdk:20.1.0`. Is it possible you run on a GraalVM 19.3.1 and use the Graal.js 20.1.0 JAR file? That might confuse the system - either use a GraalVM (that already ships with Graal.js) or run on a Stock JDK + Maven dependencies. – Christian Wirth Jun 23 '20 at 10:54
  • Right, it must be something else that forces `graal-sdk` to `19.3.1`, perhaps something from Quarkus. I got confused by the shape of the `mvn dependency:tree` output, and I'll add a note to the answer. I still think the suggestion to explicitly manage `graal-sdk` to the desired version is right. – Ladicek Jun 23 '20 at 11:08
  • Hi, again, we do that - the dependency is there. If something overrides this, I assume that is outside our control. – Christian Wirth Jun 23 '20 at 11:46
  • When I said "I still think the suggestion to explicitly manage graal-sdk to the desired version is right", I meant that in the context of the reproducer project the reporter provided. Because I actually looked at the `mvn dependency:tree` output on that project, and tried explicitly managing the `graal-sdk` version, and it helped. – Ladicek Jun 23 '20 at 15:22
  • There is a dependency on `org.graalvm.sdk:graal-sdk:jar:19.3.1:compile` reported by `mvn dependency:tree`: `[INFO] +- org.graalvm.js:js:jar:20.1.0:compile [INFO] | +- org.graalvm.regex:regex:jar:20.1.0:compile [INFO] | +- org.graalvm.sdk:graal-sdk:jar:19.3.1:compile ` After adding the dependency: `org.graalvm.sdkgraal-sdk20.1.0` to pom.xml as suggested by Ladicek, dependency on 19.3.1 is no longer reported, but the exception remains. –  Jun 24 '20 at 09:25
  • Weird. As I said, I had a different exception -- yours almost looks like it's trying to run stuff from modulepath, which certainly is not gonna work... – Ladicek Jun 24 '20 at 13:10
0

are you maybe executing that on GraalVM 19.3.1? That is known to confuse the system. Our strong suggestion is to EITHER run on a GraalVM (which automatically includes a proper version of Graal.js, no further input needed), OR run on a Stock JDK and import the respective JARs from Maven. If you import (a different version of) our Jars from maven on a GraalVM, then you might run into conflicts like that.

Christian Wirth
  • 286
  • 1
  • 6
  • `io.quarkus:quarkus-core:jar:1.5.2.Final:compile` brings the dependency on `org.graalvm.sdk:graal-sdk:jar:19.3.1:compile`. It can be seen in a dependency tree generated for just scaffolded quarkus project (i.e. with pom.xml without dependency on `org.graalvm.js:js`, `org.graalvm.js:js-scriptengine`, `org.graalvm.truffle:truffle-api` –  Jun 24 '20 at 13:04
  • I've reported bugs at: - https://github.com/quarkusio/quarkus/issues/10226 - https://github.com/oracle/graal/issues/2597 –  Jun 24 '20 at 15:28