You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: JSONRPCUtils.getAndValidateId throws and catches NumberFormatException for every SSE event when id is a string (client default) #1253
toJsonRPCRequest uses UUID.randomUUID().toString() when requestId is null
The server echoes that id on each streamed response. For every event: SSEEventListener.onMessage -> parseAndHandleMessage -> JSONRPCUtils.parseResponseEvent -> getAndValidateId
if (jsonRpc.get("id").isJsonPrimitive()) {
try {
id = jsonRpc.get("id").getAsInt();
} catch (UnsupportedOperationException | NumberFormatException | IllegalStateExceptione) {
id = jsonRpc.get("id").getAsString();
}
}
getAsInt() on a UUID string always throws, so the exception path is the normal path.
The result is correct, but each event allocates an exception and fills its stack trace.
Version: 1.4.0.Final
Suggested fix: check the primitive type before parsing, e.g.
JsonPrimitivep = jsonRpc.getAsJsonPrimitive("id");
id = p.isNumber() ? p.getAsInt() : p.getAsString();
Optionally, allow callers to supply a request id / id generator in JSONRPCTransport instead of hardcoding null in createPostBuilder.
The fix is in getAndValidateId() in JSONRPCUtils — replace the try/catch with a type check before parsing:
com.google.gson.JsonPrimitivep = jsonRpc.getAsJsonPrimitive("id");
id = p.isNumber() ? p.getAsInt() : p.getAsString();
This eliminates the NumberFormatException on every SSE event for UUID-based string IDs without changing the result. Will include a regression test. Let me know if you'd prefer a different approach.
Thanks @sumitvairagar, your proposed approach makes sense. I’ve confirmed that the default UUID request IDs trigger a caught NumberFormatException on each streamed response. I’ll assign this to you.
One detail to account for: the change will preserve numeric string IDs such as "123" as strings, whereas the current code converts them to integers. Please update the existing tests accordingly and include coverage for UUID strings, numeric strings, and numeric IDs.
Let’s keep this focused on the parsing fix; a configurable request-ID generator can be considered separately.
Addressed Kabir's feedback — numeric string IDs like "123" are still converted to Integer via a precompiled pattern check, so existing behaviour is preserved. Regression tests cover all three cases: UUID string ID, numeric string ID, and JSON number literal.
Activity
sumitvairagar commentedon Oct 31, 2026
Hi @ehsavoie @kabir 👋
I'd like to work on this one.
The fix is in
getAndValidateId()inJSONRPCUtils— replace the try/catch with a type check before parsing:This eliminates the
NumberFormatExceptionon every SSE event for UUID-based string IDs without changing the result. Will include a regression test. Let me know if you'd prefer a different approach.kabir commentedon Nov 2, 2026
Thanks @sumitvairagar, your proposed approach makes sense. I’ve confirmed that the default UUID request IDs trigger a caught NumberFormatException on each streamed response. I’ll assign this to you.
One detail to account for: the change will preserve numeric string IDs such as "123" as strings, whereas the current code converts them to integers. Please update the existing tests accordingly and include coverage for UUID strings, numeric strings, and numeric IDs.
Let’s keep this focused on the parsing fix; a configurable request-ID generator can be considered separately.
sumitvairagar commentedon Nov 2, 2026
PR raised: #1254
Addressed Kabir's feedback — numeric string IDs like "123" are still converted to Integer via a precompiled pattern check, so existing behaviour is preserved. Regression tests cover all three cases: UUID string ID, numeric string ID, and JSON number literal.
fix(jsonrpc): avoid NumberFormatException on every SSE event for stri…