Activiti/Activiti · warning · JSONException

e

Error message

e

What it means

Thrown by JSONArray.write(Writer) when the underlying Writer raises an IOException during serialization. The library wraps the IOException into a JSONException whose message is just 'e' (the exception's toString), so the real cause is in the wrapped cause.

Solutions

  1. Call getCause() on the JSONException to get the original IOException and address it (closed stream, disk full, broken pipe).
  2. Ensure the Writer is open and the underlying connection (HTTP response, socket, file) is still writable for the whole serialization.
  3. Buffer the JSON into a String (array.toString()) before writing to fragile streams.
  4. Wrap the write call in try-catch and log the cause chain.

Example fix

// before
jsonArray.write(writer);
// after
try {
    writer.write(jsonArray.toString());
} catch (IOException e) {
    log.warn("Client gone / stream closed: " + e.getMessage());
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (writer == null) throw new IllegalArgumentException("writer is null");

Try / catch

try { arr.write(writer); } catch (JSONException e) { IOException cause = (IOException) e.getCause(); log.warn("JSON write failed", cause); }

Prevention

When it happens

Trigger: Writing a JSONArray to a Writer whose I/O fails mid-serialization: closed stream, disk full, broken pipe (e.g. servlet response already committed/closed), network socket error.

Common situations: Serializing large arrays to HTTP response output streams that the client closed; writing to a FileWriter on a full disk; reusing a closed Writer.

Related errors


AI-assisted analysis of Activiti/Activiti@56435b1a97 (2026-09-09). Data as JSON: /api/errors/8f6c46db3b788b9d. Report an issue: GitHub.

Appendix: source

Thrown at activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/util/json/JSONArray.java:884

            for (int i = 0; i < len; i += 1) {
                if (b) {
                    writer.write(',');
                }
                Object v = this.myArrayList.get(i);
                if (v instanceof JSONObject) {
                    ((JSONObject) v).write(writer);
                } else if (v instanceof JSONArray) {
                    ((JSONArray) v).write(writer);
                } else {
                    writer.write(JSONObject.valueToString(v));
                }
                b = true;
            }
            writer.write(']');
            return writer;
        } catch (IOException e) {
            throw new JSONException(e);
        }
    }
}

View on GitHub (pinned to 56435b1a97)