eclipse-vertx/vert.x · error · DecodeException
${e.getMessage()}
Error message
${e.getMessage()} What it means
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.
Source
Thrown at vertx-core/src/main/java/io/vertx/core/spi/json/JsonCodec.java:96
}
/**
* Decode JSON from the given {@link InputStream} to an object of the specified type.
* <p>
* The input is expected to be UTF-8 encoded.
* <p>
* The codec does not close or flush the stream; the caller retains ownership.
*
* @param in the input stream containing UTF-8 encoded JSON
* @param clazz the required object's class
* @return the decoded instance
* @throws DecodeException anything preventing the decoding
*/
default <T> T fromStream(InputStream in, Class<T> clazz) throws DecodeException {
try {
return fromBuffer(Buffer.buffer(in.readAllBytes()), clazz);
} catch (IOException e) {
throw new DecodeException(e.getMessage(), e);
}
}
/**
* Decode JSON from the given {@link InputStream}.
* <p>
* The input is expected to be UTF-8 encoded.
* <p>
* The codec does not close or flush the stream; the caller retains ownership.
*
* @param in the input stream containing UTF-8 encoded JSON
* @return a JSON element which can be a {@link JsonArray}, {@link JsonObject}, {@link String}, etc.
* @throws DecodeException anything preventing the decoding
*/
default Object fromStream(InputStream in) throws DecodeException {
return fromStream(in, Object.class);
}
View on GitHub (pinned to fb308bd8c3)
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.
Example fix
// before
MyDto dto = codec.fromStream(in, MyDto.class); // IOException wrapped as DecodeException
// after
byte[] bytes;
try {
bytes = in.readAllBytes();
} catch (IOException e) {
bytes = retryFetch();
}
MyDto dto = codec.fromBuffer(Buffer.buffer(bytes), MyDto.class); Defensive patterns
Strategy: try-catch
Validate before calling
// read bytes yourself so IOException is handled where you can retry byte[] bytes = in.readAllBytes(); codec.fromBuffer(Buffer.buffer(bytes), MyDto.class);
Try / catch
try {
return codec.fromStream(in, MyDto.class);
} catch (DecodeException e) {
if (e.getCause() instanceof java.io.IOException) {
throw new java.io.UncheckedIOException((java.io.IOException) e.getCause()); // read problem, retry upstream
}
throw e; // actual JSON parse problem
} Prevention
- 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.
When it happens
Trigger: Calling fromStream(in, clazz) where the InputStream fails mid-read: a closed socket, broken file handle, or interrupted pipe.
Common situations: 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.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- Failed to decode:${e.getMessage()}
- ${e.getMessage()}
- workerPoolSize must be > 0
- Failed to unpack ${url}
- Failed to copy ${from} to ${to}
AI-assisted analysis of eclipse-vertx/vert.x@fb308bd8c3 (2026-09-06).
Data as JSON: /api/errors/10796e2e74cb62a7.
Report an issue: GitHub.