Repository navigation
Description
[Bug]: ClassCastException in DataPartParser when deserializing ToolResultBlock in Java-to-Java A2A communication
Describe the bug
In a Java-to-Java A2A (Agent-to-Agent) communication scenario, the DataPartParser fails with a ClassCastException when processing a message that contains a ToolResultBlock.
The root cause is that when DataPartParser deserializes the output field of a ToolResultBlock from JSON, it initially becomes a List<LinkedHashMap>. The code then attempts to directly cast this list to List<ContentBlock>, which is invalid in Java and triggers the exception during stream processing or access.
To Reproduce
Steps to reproduce the behavior:
- Create a Supervisor agent and a Sub-agent, both using the Java SDK.
- Set up A2A communication between them (e.g., via Nacos or direct gRPC).
- In the Sub-agent, use a
ReActAgentand configureStreamOptionsto includeEventType.TOOL_RESULT. - Trigger a tool call in the Sub-agent that returns content.
- The Supervisor agent will crash with a
ClassCastExceptionupon receiving and parsing the sub-agent's response.
Expected behavior
The DataPartParser should correctly deserialize the list of maps into a list of ContentBlock objects by leveraging the polymorphic deserialization capabilities of the JsonCodec (Jackson), respecting the @JsonTypeInfo defined in ContentBlock.
Error messages/Stack trace
java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class io.agentscope.core.message.ContentBlock
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178)
at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:722)
at io.agentscope.core.a2a.agent.message.DataPartParser.parseToToolResultBlock(DataPartParser.java:91)
Proposed Fix
Modify DataPartParser.java to perform explicit conversion of each list item using the project's global JsonCodec instead of a direct raw cast.
// Current problematic code in DataPartParser.java (line 91 in v1.0.12):
} else if (output instanceof List) {
@SuppressWarnings("unchecked")
List<ContentBlock> outputList = (List<ContentBlock>) output;
builder.output(outputList);
}
// Proposed fix:
} else if (output instanceof List<?> rawList) {
List<ContentBlock> contentBlocks = new ArrayList<>(rawList.size());
for (Object item : rawList) {
if (item instanceof ContentBlock cb) {
contentBlocks.add(cb);
} else if (item != null) {
// Leverage Jackson's polymorphic deserialization based on the 'type' field
ContentBlock cb = JsonUtils.getJsonCodec().convertValue(item, ContentBlock.class);
if (cb != null) {
contentBlocks.add(cb);
}
}
}
builder.output(contentBlocks);
}System Information:
- AgentScope-Java Version: v1.0.12
- Environment: Java-to-Java A2A communication
- Component: agentscope-extensions-a2a-client
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
breno-concrete commentedon Sep 24, 2026
Hi, I'd like to work on this. I will apply the fix suggested in the issue (convert each item via JsonUtils.getJsonCodec().convertValue() instead of the raw cast) and add a regression test. Opening a PR shortly.
oss-maintainer commentedon Sep 24, 2026
Issue Evaluation
Category:
bug| Status: Confirmed (reviewed againstmain@3c1c29c01, static code review, no runtime reproduction)Root cause.
DataPartParser.parseToToolResultBlockstill does an unchecked cast of the decodedoutputlist:agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/main/java/io/agentscope/core/a2a/agent/message/DataPartParser.java:80-96Because of erasure the cast succeeds for a
List<LinkedHashMap>and theClassCastExceptiononly fires when a consumer reads an element asContentBlock, which matches the reported stack trace.The polymorphic path the reporter suggests is available:
ToolResultBlock.outputis typedList<ContentBlock>(agentscope-core/src/main/java/io/agentscope/core/message/ToolResultBlock.java:40-55),ContentBlockcarries@JsonTypeInfo(use=NAME, property="type")+@JsonSubTypes(agentscope-core/src/main/java/io/agentscope/core/message/ContentBlock.java:46-58), andJsonCodec.convertValuehandles map → typed conversion (agentscope-core/src/main/java/io/agentscope/core/util/JsonCodec.java:91-102).Not already fixed on main. An equivalent per-element conversion exists only in a non-
mainhistory (c8797a799 refactor(a2a)!: migrate A2A modules to SDK 1.0.0.Final, contained byremotes/pr/2311), which normalizes throughMessageConvertUtil.contentBlockFromProtobufSafeValue. The onlymaincommit touching this file is3c1c29c01. We could not tie the closed PR #1346 to any commit onmain; its behaviour is not present here.Impact. Any Java↔Java A2A call that returns a
ToolResultBlockwith list-typed output throughDataPartbreaks at stream-consumption time;agentscope-extensions-a2a-clientis a published reactor module (agentscope-distribution/agentscope-bom/pom.xml:102-114), so this is not an examples-only path.Severity: medium (crash on an integration path, narrow and deterministic fix).
Suggested fix shape. Iterate
List<?>: keep items alreadyinstanceof ContentBlock, convert the rest viaJsonUtils.getJsonCodec().convertValue(item, ContentBlock.class), and pass the resulting list to the builder — the reporter's snippet matches what the code supports. Add the missing regression case inagentscope-extensions-a2a-client/src/test/java/io/agentscope/core/a2a/agent/message/DataPartParserTest.java(existing coverage at:120-142only feeds an already-typedList<ContentBlock>, never a list of maps).No automated fix PR from us this time. A contributor (@breno-concrete) has already claimed this fix in the thread, so a bot PR would duplicate their work. If no PR lands, reply
/approveand we will generate one against the fix shape above.Automated evaluation by github-manager-bot.
oss-maintainer commentedon Sep 27, 2026
Status: 72 h feedback window expired — no automated PR will be generated, the proposal window here is closed
The evaluation above (
5823097511, posted 2026-09-24T22:13:13Z) reached its 72-hour feedback limit at 2026-09-27T22:13:13Z. Nobody replied in the thread, and no line in it starts with an approve, revise or reject command, so per our workflow we skip PR generation and no competing PR will be filed from this proposal window. No action is needed from anyone.The fix path stays community-owned, which was already the case when the evaluation was written. PR #3289 by @breno-concrete (fix(a2a): convert ToolResultBlock output maps to ContentBlock in DataParser) is still
OPENand unmerged at headebf05d7252(mergeable_state=clean, last updated 2026-09-25T13:54:24Z), and the earlier attempt PR #1346 by @JGoP-L was closed unmerged on 2026-08-21 at headf256958aaf. Filing a bot PR into the same parser seam now would collide with #3289 rather than add to it.Standing this window down is a timing call, not a verdict on the report. The evaluation confirmed the defect:
DataPartParser.parseToToolResultBlockstill casts the decodedoutputlist toList<ContentBlock>unchecked, so erasure lets aList<LinkedHashMap>through and theClassCastExceptionsurfaces at the first element read — which is what the reporter's stack trace shows. That conclusion is unchanged by the window closing. If a first-party patch is wanted anyway, replying here with a direction (a revise command carrying the chosen converter shape, or an explicit go-ahead) is enough to get a spec and a PR generated against currentmain; the bot simply stops waiting on this thread.Automated by github-manager-bot