{"record":{"id":"d1536ec05a88745b","repo":"Activiti/Activiti","slug":"nesting-too-deep","errorCode":null,"errorMessage":"Nesting too deep.","messagePattern":"Nesting too deep\\.","errorType":"exception","errorClass":"JSONException","httpStatus":null,"severity":"error","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/util/json/JSONWriter.java","lineNumber":286,"sourceCode":"            throw new JSONException(\"Nesting error.\");\n        }\n        char m = this.stack[this.top - 1] == null ? 'a' : 'k';\n        if (m != c) {\n            throw new JSONException(\"Nesting error.\");\n        }\n        this.top -= 1;\n        this.mode = this.top == 0 ? 'd' : this.stack[this.top - 1] == null ? 'a' : 'k';\n    }\n\n    /**\n     * Push an array or object scope.\n     *\n     * @throws JSONException\n     *           If nesting is too deep.\n     */\n    private void push(JSONObject jo) throws JSONException {\n        if (this.top >= maxdepth) {\n            throw new JSONException(\"Nesting too deep.\");\n        }\n        this.stack[this.top] = jo;\n        this.mode = jo == null ? 'a' : 'k';\n        this.top += 1;\n    }\n\n    /**\n     * Append either the value <code>true</code> or the value <code>false</code> .\n     *\n     * @param b\n     *          A boolean.\n     * @return this\n     * @throws JSONException\n     */\n    public JSONWriter value(boolean b) throws JSONException {\n        return this.append(b ? \"true\" : \"false\");\n    }\n","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/util/json/JSONWriter.java#L268-L304","documentation":"JSONWriter maintains a fixed-size scope stack with a configurable maxdepth to protect against stack overflow and maliciously deep input. push(jo) throws \"Nesting too deep.\" when object() or array() is called while the current nesting depth already equals maxdepth.","triggerScenarios":"Calling writer.object()/writer.array() when nesting depth has reached the writer's maxdepth (default limit), typically while serializing deeply recursive structures like trees or linked structures.","commonSituations":"Serializing recursive object graphs (parent/child trees, linked lists) with JSONWriter, or parsing/writing untrusted deeply nested JSON that exceeds the configured depth limit.","solutions":["Increase maxdepth via the JSONWriter constructor that accepts a depth limit, if the data is legitimately deep.","Flatten or restructure the data model before serialization.","Detect and cut cycles in the object graph (they inflate depth artificially).","For untrusted input, enforce a sane depth cap rather than raising the limit."],"exampleFix":"// before\nJSONWriter w = new JSONWriter(sw); // default maxdepth, deep tree overflows\n// after\nJSONWriter w = new JSONWriter(sw, 512); // raise limit for deep structures","handlingStrategy":"validation","validationCode":"if (currentDepth >= maxDepth) throw new IllegalStateException(\"structure exceeds JSONWriter max depth\");","typeGuard":null,"tryCatchPattern":"try { writer.object(); } catch (JSONException e) { if (e.getMessage().contains(\"Nesting too deep\")) { /* flatten or increase limit */ } throw e; }","preventionTips":["Configure a maxdepth sized for your data before serializing","Detect and break cycles in object graphs","Flatten recursive structures (e.g. parent -> id references) before writing"],"tags":["json","serialization","nesting","limit-exceeded"],"backgroundTag":"json-marshal-failed","analyzedSha":"56435b1a97deeafdc09dd40074b056c89fba5a8a","analyzedAt":"2026-09-09T21:00:06.703Z","contentChangedAt":"2026-09-09T21:00:06.703Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}