简体   繁体   中英

com.oracle.truffle.polyglot.PolyglotImpl (in unnamed module) cannot access class org.graalvm.polyglot.impl.AbstractPolyglotImpl

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). 在此处输入图像描述

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM