{"record":{"id":"10796e2e74cb62a7","repo":"eclipse-vertx/vert.x","slug":"e-getmessage-10796e","errorCode":null,"errorMessage":"${e.getMessage()}","messagePattern":"\\$\\{e\\.getMessage\\(\\)\\}","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/spi/json/JsonCodec.java","lineNumber":96,"sourceCode":"  }\n\n  /**\n   * Decode JSON from the given {@link InputStream} to an object of the specified type.\n   * <p>\n   * The input is expected to be UTF-8 encoded.\n   * <p>\n   * The codec does not close or flush the stream; the caller retains ownership.\n   *\n   * @param in    the input stream containing UTF-8 encoded JSON\n   * @param clazz the required object's class\n   * @return the decoded instance\n   * @throws DecodeException anything preventing the decoding\n   */\n  default <T> T fromStream(InputStream in, Class<T> clazz) throws DecodeException {\n    try {\n      return fromBuffer(Buffer.buffer(in.readAllBytes()), clazz);\n    } catch (IOException e) {\n      throw new DecodeException(e.getMessage(), e);\n    }\n  }\n\n  /**\n   * Decode JSON from the given {@link InputStream}.\n   * <p>\n   * The input is expected to be UTF-8 encoded.\n   * <p>\n   * The codec does not close or flush the stream; the caller retains ownership.\n   *\n   * @param in the input stream containing UTF-8 encoded JSON\n   * @return a JSON element which can be a {@link JsonArray}, {@link JsonObject}, {@link String}, etc.\n   * @throws DecodeException anything preventing the decoding\n   */\n  default Object fromStream(InputStream in) throws DecodeException {\n    return fromStream(in, Object.class);\n  }\n","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/spi/json/JsonCodec.java#L78-L114","documentation":"JsonCodec.fromStream decodes JSON from an InputStream by reading all bytes and delegating to fromBuffer. If the underlying stream throws an IOException while reading, it is wrapped in a DecodeException whose message is the IOException's message.","triggerScenarios":"Calling fromStream(in, clazz) where the InputStream fails mid-read: a closed socket, broken file handle, or interrupted pipe.","commonSituations":"Reading JSON from a network stream that the peer closed; reading a file that was deleted/truncated while streaming; wrapping a HttpURLConnection input stream after a connection reset.","solutions":["Check stream availability/lifecycle before decoding (ensure the source connection/file is open and readable).","Read bytes into a Buffer first yourself and use fromBuffer, handling IOException where you can retry.","Retry the fetch of the stream (network blips) rather than treating it as a JSON syntax problem.","Note: a JSON syntax error surfaces directly from fromBuffer as DecodeException — distinguish read failures (wrapped IOException) from parse failures."],"exampleFix":"// before\nMyDto dto = codec.fromStream(in, MyDto.class); // IOException wrapped as DecodeException\n// after\nbyte[] bytes;\ntry {\n  bytes = in.readAllBytes();\n} catch (IOException e) {\n  bytes = retryFetch();\n}\nMyDto dto = codec.fromBuffer(Buffer.buffer(bytes), MyDto.class);","handlingStrategy":"try-catch","validationCode":"// read bytes yourself so IOException is handled where you can retry\nbyte[] bytes = in.readAllBytes();\ncodec.fromBuffer(Buffer.buffer(bytes), MyDto.class);","typeGuard":null,"tryCatchPattern":"try {\n  return codec.fromStream(in, MyDto.class);\n} catch (DecodeException e) {\n  if (e.getCause() instanceof java.io.IOException) {\n    throw new java.io.UncheckedIOException((java.io.IOException) e.getCause()); // read problem, retry upstream\n  }\n  throw e; // actual JSON parse problem\n}","preventionTips":["Check stream/source availability before decoding.","Distinguish read failures (cause is IOException) from parse failures.","Retry the data fetch rather than the decode for transient stream errors."],"tags":["json","io","decode-exception"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}