oracle/graal · error · IllegalStateException

Cannot mix JNI scopes: <this> and <top>

Error message

Cannot mix JNI scopes: <this> and <top>

What it means

Error "Cannot mix JNI scopes: <this> and <top>" thrown in oracle/graal.

Source

Thrown at sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java:126

        return scope.leaf;
    }

    /**
     * Enters the scope of an native method call.
     */
    @SuppressWarnings({"unchecked", "this-escape"})
    public JNIMethodScope(String scopeName, JNIEnv env) {
        Objects.requireNonNull(scopeName, "ScopeName must be non null.");
        this.scopeName = scopeName;
        JNIMethodScope top = topScope.get();
        this.env = env;
        if (top == null) {
            top = this;
            parent = null;
            topScope.set(this);
        } else {
            if (top.env != this.env) {
                throw new IllegalStateException("Cannot mix JNI scopes: " + this + " and " + top);
            }
            parent = top.leaf;
        }
        top.leaf = this;
        JNIUtil.trace(1, "HS->%s[enter]: %s", JNIUtil.getFeatureName(), scopeName);
    }

    /**
     * Used to copy the handle to an object return value out of the JNI local frame.
     */
    private JObject objResult;

    public void setObjectResult(JObject obj) {
        objResult = obj;
    }

    @SuppressWarnings("unchecked")
    public <R extends JObject> R getObjectResult() {

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Fix the condition reported by the error: Cannot mix JNI scopes: <this> and <top>
  2. Check the throwing call site and ensure its documented preconditions (argument values, types, environment, or configuration) are satisfied before the call.

Example fix

Validate inputs and environment so that the failing condition does not occur: Cannot mix JNI scopes: <this> and <top>

When it happens

Trigger: Thrown at sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java:126 when the library encounters an invalid state.

Common situations: Occurs when a caller violates the contract guarded by this check: Cannot mix JNI scopes: <this> and <top>


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