oracle/graal · error · IllegalArgumentException

Expected an EspressoExternalResolvedJavaModule, got {}

Error message

Expected an EspressoExternalResolvedJavaModule, got {}

What it means

Thrown by EspressoExternalResolvedJavaModule.isOpen(String, ResolvedJavaModule) when the accessingModule argument is not an EspressoExternalResolvedJavaModule. The two-argument isOpen forwards the accessing module's guest module Value into the guest j.l.Module.isOpen(String, Module) call, so only module wrappers created by the same Espresso vmaccess layer (which carry that Value) are usable; modules resolved by another JVMCI backend (e.g. the host compiler's own module meta objects) are rejected. safeGetClass reports the actual class, or 'null' when safe.

Source

Thrown at espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalResolvedJavaModule.java:73

    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public boolean isOpen(String packageName) {
        Objects.requireNonNull(packageName);
        Value packageNameValue = access.invokeJVMCIHelper("toGuestString", packageName);
        return access.java_lang_Module_isOpen_String.getMirror().execute(moduleValue, packageNameValue).asBoolean();
    }

    @Override
    public boolean isOpen(String packageName, ResolvedJavaModule accessingModule) {
        Objects.requireNonNull(packageName);
        if (!(accessingModule instanceof EspressoExternalResolvedJavaModule espressoModule)) {
            throw new IllegalArgumentException("Expected an EspressoExternalResolvedJavaModule, got " + safeGetClass(accessingModule));
        }
        Value packageNameValue = access.invokeJVMCIHelper("toGuestString", packageName);
        return access.java_lang_Module_isOpen_String_Module.getMirror().execute(moduleValue, packageNameValue, espressoModule.moduleValue).asBoolean();
    }

    @Override
    public boolean isExported(String packageName) {
        Objects.requireNonNull(packageName);
        Value packageNameValue = access.invokeJVMCIHelper("toGuestString", packageName);
        return access.java_lang_Module_isExported_String.getMirror().execute(moduleValue, packageNameValue).asBoolean();
    }

    @Override
    public boolean isExported(String packageName, ResolvedJavaModule accessingModule) {
        Objects.requireNonNull(packageName);
        if (!(accessingModule instanceof EspressoExternalResolvedJavaModule espressoModule)) {
            throw new IllegalArgumentException("Expected an EspressoExternalResolvedJavaModule, got " + safeGetClass(accessingModule));
        }

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Resolve the accessing module through the same EspressoExternalVMAccess so it is an EspressoExternalResolvedJavaModule
  2. Use the single-argument isOpen(packageName) when you only need unconditional openness and cannot obtain the guest wrapper for the accessor
  3. Null-check accessingModule before the call (safeGetClass will show null)

Example fix

// before
boolean open = espressoModule.isOpen(pkg, hostBackendModule);

// after
ResolvedJavaModule guestAccessor = access.findModule(accessorClass);
boolean open = espressoModule.isOpen(pkg, guestAccessor);
Defensive patterns

Strategy: type-guard

Validate before calling

if (accessingModule == null || !(accessingModule instanceof EspressoExternalResolvedJavaModule)) {
    // fall back to unconditional form or fail with a clear diagnostic
    boolean open = module.isOpen(packageName);
    ...
}

Prevention

When it happens

Trigger: Calling isOpen(packageName, accessingModule) where accessingModule came from the host JVMCI (HostResolvedJavaModule from libgraal/HotSpot backend) or is null; mixing module objects across a pipeline that talks to both a host and the Espresso guest VM.

Common situations: Compiler configurations that consult both the host module graph and the guest module graph for readability checks; porting code from an in-process JVMCI (where any ResolvedJavaModule worked) to the external espresso-compiler-stub adapter.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/c93a336d09fa70cf. Report an issue: GitHub.