{"record":{"id":"377b0476a0f50afd","repo":"eclipse-vertx/vert.x","slug":"invalid-json-array-buf","errorCode":null,"errorMessage":"Invalid JSON array: ${buf}","messagePattern":"Invalid JSON array: (.+?)","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/json/JsonArray.java","lineNumber":95,"sourceCode":"  public JsonArray(List list) {\n    if (list == null) {\n      throw new NullPointerException();\n    }\n    this.list = list;\n  }\n\n  /**\n   * Create an instance from a Buffer of JSON.\n   *\n   * @param buf the buffer of JSON.\n   */\n  public JsonArray(Buffer buf) {\n    if (buf == null) {\n      throw new NullPointerException();\n    }\n    fromBuffer(buf);\n    if (list == null) {\n      throw new DecodeException(\"Invalid JSON array: \" + buf);\n    }\n  }\n\n  /**\n   * Create a JsonArray containing an arbitrary number of values.\n   *\n   * @param values The objects into JsonArray.\n   * @throws NullPointerException if the args is null.\n   */\n  public static JsonArray of(Object... values) {\n    // implicit nullcheck of values\n    if (values.length == 0) {\n      return new JsonArray();\n    }\n\n    JsonArray arr = new JsonArray(new ArrayList<>(values.length));\n    for(int i = 0; i< values.length; ++i) {\n      arr.add(values[i]);","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/json/JsonArray.java#L77-L113","documentation":"The JsonArray(Buffer) constructor decodes the buffer as JSON; if decoding does not produce an array (object, scalar, empty or malformed bytes), the internal list stays null and DecodeException(\"Invalid JSON array: <buf>\") is thrown.","triggerScenarios":"new JsonArray(buffer) where the Buffer holds a JSON object, an empty payload, or corrupt/truncated bytes — e.g. an HTTP response body that is not an array.","commonSituations":"Consuming an HTTP endpoint that returns {\"error\":...} while the client expects a JSON array; empty 200 responses; binary/corrupt payloads from a queue or file.","solutions":["Check the buffer content: if it decodes to an object use JsonObject(Buffer) instead.","Guard against empty buffers before parsing.","Log/print the buffer (toString) to see the actual payload and fix the producer or the expected type.","Catch DecodeException and fall back to alternate parsing for untrusted sources."],"exampleFix":"// before\nJsonArray arr = new JsonArray(body); // body might be {}\n// after\nif (body.length() > 0 && body.toString().trim().startsWith(\"[\")) {\n  JsonArray arr = new JsonArray(body);\n}","handlingStrategy":"validation","validationCode":"boolean isJsonArrayBuffer(Buffer b) { return b != null && b.length() > 0 && b.toString().trim().startsWith(\"[\"); }","typeGuard":"JsonArray safeArray(Buffer buf) { return buf != null && buf.length() > 0 && buf.toString().trim().startsWith(\"[\") ? new JsonArray(buf) : null; }","tryCatchPattern":"try { arr = new JsonArray(buf); } catch (DecodeException e) { /* inspect buf.toString(), handle non-array payload */ }","preventionTips":["Reject empty buffers before parsing","Confirm the endpoint actually returns a JSON array (Content-Type + shape check)","Log payload previews on decode failure to spot producer regressions"],"tags":["json","decode","jsonarray","buffer"],"backgroundTag":"json-decode-failed","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}