oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.4k stars 1.64k forks source link

Tracking Issue: IntelliJ IDEA won't run unit tests correctly that use commercial sandbox profiles like UNTRUSTED after the move to 23.1 #7779

Open FWiesner opened 1 year ago

FWiesner commented 1 year ago

(this issue is for reference for other stumbling over the same problem, not a GraalVM issue)

Background: we have a project that is based on Maven (3.9.2) and try migrating it from GraalVM 23.0 to 23.1. Due to the packaging changes, with 23.1 the polyglot dependencies come from the Maven dependency graph and are no more installed via gu. We use SandboxPolicy.UNSTRUSTED since 23.0 and have several JUnit 5 test cases that rely on the presence of the profile. These unit tests were executable in IntelliJ, but will not run anymore after the upgrade to 23.1.

Internal Analysis Result: the GraalVM team (@chumer) was able to reproduce the issue and identified that the regression is caused by IntelliJ IDEA. In particular GraalVM 23.1 uses the JPMS ServiceLoader approach to find SPIs. But, this requires that the jars are on the module path instead of the class path. This means that the jars that are referenced by

<dependency>
  <groupId>org.graalvm.polyglot</groupId>
  <artifactId>js-isolate</artifactId>
  <version>${graalvm-version}</version>
  <type>pom</type>
  <scope>runtime</scope>
</dependency>

should all end up on the module-path. When having a main class under src/main/java this works correctly and the SPIs can be found. But when IntelliJ on the other hand renders a unit test run configuration, the dependencies end up on the class path instead, breaking the SPI resolution.

You then get something like this, even when using GraalVM (not GraalVM Community) and only in IntelliJ (Maven command line testing works):

java.lang.ExceptionInInitializerError
    at <YOUR TEST CLASS>
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.IllegalArgumentException: The Builder.sandbox(SandboxPolicy) is set to UNTRUSTED, but the GraalVM community edition supports only sandbox policy TRUSTED or CONSTRAINED.In order to resolve this switch to a less strict sandbox policy using Builder.sandbox(SandboxPolicy).
    at com.oracle.truffle.polyglot.PolyglotEngineException.illegalArgument(PolyglotEngineException.java:129)
    at com.oracle.truffle.polyglot.PolyglotImpl.validateSandbox(PolyglotImpl.java:391)
    at com.oracle.truffle.polyglot.PolyglotImpl.buildEngine(PolyglotImpl.java:274)
    at org.graalvm.polyglot/org.graalvm.polyglot.Engine$Builder.build(Engine.java:752)
    at <YOUR CODE UNDER TEST>
    ... <n> more
FWiesner commented 1 year ago

Issue in Jetbrains' issue tracker: https://youtrack.jetbrains.com/issue/IDEA-337648/Unit-Testing-broken-when-using-GraalVM-23.1-polyglot-projects

selhagani commented 1 year ago

Hi @FWiesner, thank you for reporting this. The link you shared is not accessible.

FWiesner commented 1 year ago

@selhagani You need a registered user in their issue tracker to see it