{"record":{"id":"0749263c443202aa","repo":"oracle/graal","slug":"cannot-mix-jni-scopes-this-and-top","errorCode":null,"errorMessage":"Cannot mix JNI scopes: <this> and <top>","messagePattern":"Cannot mix JNI scopes: <this> and <top>","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java","lineNumber":126,"sourceCode":"        return scope.leaf;\n    }\n\n    /**\n     * Enters the scope of an native method call.\n     */\n    @SuppressWarnings({\"unchecked\", \"this-escape\"})\n    public JNIMethodScope(String scopeName, JNIEnv env) {\n        Objects.requireNonNull(scopeName, \"ScopeName must be non null.\");\n        this.scopeName = scopeName;\n        JNIMethodScope top = topScope.get();\n        this.env = env;\n        if (top == null) {\n            top = this;\n            parent = null;\n            topScope.set(this);\n        } else {\n            if (top.env != this.env) {\n                throw new IllegalStateException(\"Cannot mix JNI scopes: \" + this + \" and \" + top);\n            }\n            parent = top.leaf;\n        }\n        top.leaf = this;\n        JNIUtil.trace(1, \"HS->%s[enter]: %s\", JNIUtil.getFeatureName(), scopeName);\n    }\n\n    /**\n     * Used to copy the handle to an object return value out of the JNI local frame.\n     */\n    private JObject objResult;\n\n    public void setObjectResult(JObject obj) {\n        objResult = obj;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public <R extends JObject> R getObjectResult() {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java#L108-L144","documentation":"Error \"Cannot mix JNI scopes: <this> and <top>\" thrown in oracle/graal.","triggerScenarios":"Thrown at sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java:126 when the library encounters an invalid state.","commonSituations":"Occurs when a caller violates the contract guarded by this check: Cannot mix JNI scopes: <this> and <top>","solutions":["Fix the condition reported by the error: Cannot mix JNI scopes: <this> and <top>","Check the throwing call site and ensure its documented preconditions (argument values, types, environment, or configuration) are satisfied before the call."],"exampleFix":"Validate inputs and environment so that the failing condition does not occur: Cannot mix JNI scopes: <this> and <top>","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}