[Bug]: ctx.map returns MapResult items as LinkedHashMap instead of the declared result type
维护者通常 1 天内回复
评估
调研方向
Read sdk/src/main/java/software/amazon/lambda/durable/operation/MapOperation.java and trace how itemResultType reaches the serialized MapResult. Start with the existing MapIntegrationTest cases and add coverage for a POJO item on first execution and replay. Done means both paths return items as the declared type; an open pull request is already linked to this issue.
由索引模型根据 Issue 内容生成。
描述
Expected Behavior
DurableContext.map(name, items, Class<O>, fn, config) returns a MapResult<O> whose items are instances of O. This holds on the first execution and on replay.
Actual Behavior
When O is a POJO or record, each item in the returned MapResult is a java.util.LinkedHashMap. Reading an item as O throws ClassCastException.
This happens on the first execution, not only on replay. On completion, MapOperation replaces its result with a serialize-then-deserialize copy, so the first execution returns the same value that replay returns.
Steps to Reproduce
public record Payload(String value) {}
@Test
void itemIsDeclaredType() {
var runner = LocalDurableTestRunner.create(String.class, (input, context) -> {
var result = context.map(
"m",
List.of("a", "b"),
Payload.class,
(item, index, ctx) -> new Payload(item),
MapConfig.builder().build());
Object first = result.getResult(0);
return first.getClass().getName();
});
var result = runner.runUntilComplete("x");
assertEquals(ExecutionStatus.SUCCEEDED, result.getStatus());
assertEquals(Payload.class.getName(), result.getResult(String.class));
}
The test fails:
expected: <...$Payload> but was: <java.util.LinkedHashMap>
SDK Version
main at 3.0.1-SNAPSHOT. Also reported on 2.x. On 1.2.1 the first execution returns Payload, and replay of a completed map returns LinkedHashMap.
Java Version
17
Is this a regression?
Yes
Last Working Version
None fully. 1.2.1 is correct on the first execution and wrong on replay.
Additional Context
The cause is in MapOperation. The constructor passes new TypeToken<>() {} to its superclass as the result type (sdk/src/main/java/software/amazon/lambda/durable/operation/MapOperation.java, line 83).
- That anonymous class is created inside the generic class
MapOperation<I, O>. - So the captured type is
MapResult<O>, withOstill a type variable. - So Jackson has no item type and deserializes each item as a
LinkedHashMap. - The constructor receives the caller's
TypeToken<O>asitemResultType. It stores it but does not use it to build the result type.
The existing MapIntegrationTest cases use String and Integer items. Jackson deserializes those correctly without type information, so the tests do not catch the bug.
The JavaScript SDK also returns the serdes round-trip of the batch result on both paths. Its items are plain JSON objects, which already match the declared TypeScript type. So keeping the round-trip and fixing the item type keeps Java consistent with JavaScript.
Suggested fix: build a parameterized MapResult<O> type from itemResultType, for example by letting TypeToken be created from a java.lang.reflect.Type. Add integration tests with a POJO item type for the first execution and for replay.
- 主要语言
- Java
- 星标
- 28
- 派生
- 18
- 平均合并
- 16 小时 53 分钟
- 30 天内合并 PR
- 63
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aws/aws-durable-execution-sdk-java 的其他 Issue
-
bug pkg:conformance
难度 2/5 1-3 小时 新手友好度 76/100
aws/aws-durable-execution-sdk-java#844 ·
维护者通常 1 天内回复
-
documentation pkg:sdk
难度 1/5 1-3 小时 新手友好度 88/100
aws/aws-durable-execution-sdk-java#645 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
aws/aws-durable-execution-sdk-java#300 ·
维护者通常 1 天内回复
-
bug pkg:telemetry
难度 4/5 3-5 天 新手友好度 54/100
aws/aws-durable-execution-sdk-java#877 ·
维护者通常 1 天内回复
-
[Feature]: Add a unified OtelPlugin factory with execution defaults可能已有人在做 @zhongkechen 于 1 天前认领。 未关闭enhancement needs-triage
难度 4/5 3-5 天 新手友好度 25/100
aws/aws-durable-execution-sdk-java#872 ·
维护者通常 1 天内回复
查看 aws/aws-durable-execution-sdk-java 的全部 Issue
相似的 Issue
-
needs-area-label
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 2 天内回复
-
enhancement Java macOS
难度 2/5 1-3 小时 新手友好度 78/100
freerouting/freerouting#1079 ·
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
apache/maven-enforcer#1074 ·
维护者通常 1 天内回复
-
Gradle liquibaseDiffChangelog drops jhi_date_time_wrapper可能已有人在做 @mraible 今天认领。 未关闭area: triage theme: undefined
难度 2/5 1-3 小时 新手友好度 88/100
jhipster/generator-jhipster#35998 ·
维护者通常 1 天内回复