Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static A2AResponse<?> parseResponseBody(String body, String method) throw
String version = getAndValidateJsonrpc(jsonRpc);
Object id = getAndValidateId(jsonRpc);
JsonElement paramsNode = jsonRpc.get("result");
if (jsonRpc.has("error")) {
if (jsonRpc.has("error") && !jsonRpc.get("error").isJsonNull()) {
return parseError(jsonRpc.getAsJsonObject("error"), id, method);
}
Comment on lines +309 to 311
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation performs multiple lookups for the 'error' field. A more efficient approach is to retrieve the element once. Since the JSON-RPC specification defines the error field as an object, we can rely on this constraint and avoid additional defensive type checks for primitives. This same pattern should be applied to parseResponseEvent at line 293.

        JsonElement errorNode = jsonRpc.get("error");
        if (errorNode != null && !errorNode.isJsonNull()) {
            return parseError(errorNode.getAsJsonObject(), id, method);
        }
References
  1. When handling return types constrained by a formal specification, it is acceptable to rely on the specification's constraints rather than adding defensive checks for types that the specification explicitly excludes.

switch (method) {
Expand Down
Loading