{"record":{"id":"ac69ffbef15e5055","repo":"oracle/graal","slug":"unexpected-jni-scope-topscope-get","errorCode":null,"errorMessage":"Unexpected JNI scope: <topScope.get()>","messagePattern":"Unexpected JNI scope: <topScope\\.get\\(\\)>","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java","lineNumber":154,"sourceCode":"     */\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() {\n        return (R) objResult;\n    }\n\n    @Override\n    public void close() {\n        JNIUtil.trace(1, \"HS->%s[ exit]: %s\", getFeatureName(), scopeName);\n        HSObject.invalidate(locals);\n        if (parent == null) {\n            if (topScope.get() != this) {\n                throw new IllegalStateException(\"Unexpected JNI scope: \" + topScope.get());\n            }\n            topScope.set(null);\n        } else {\n            JNIMethodScope top = parent;\n            while (top.parent != null) {\n                top = top.parent;\n            }\n            top.leaf = parent;\n        }\n    }\n\n    public final int depth() {\n        int depth = 0;\n        JNIMethodScope ancestor = parent;\n        while (ancestor != null) {\n            depth++;\n            ancestor = ancestor.parent;\n        }","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java#L136-L172","documentation":"Error \"Unexpected JNI scope: <topScope.get()>\" thrown in oracle/graal.","triggerScenarios":"Thrown at sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java:154 when the library encounters an invalid state.","commonSituations":"Occurs when a caller violates the contract guarded by this check: Unexpected JNI scope: <topScope.get()>","solutions":["Fix the condition reported by the error: Unexpected JNI scope: <topScope.get()>","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: Unexpected JNI scope: <topScope.get()>","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"}