arextest / arextest/arex-agent-java

[Bug] TypeUtil.mapToString 方法仅使用第一个非空值的类型来代表 Map<String, Object>,导致异构值反序列化失败

Open
#620 1 comment 0 reactions 0 assignees View on GitHub
bug :lady_beetle:
Dominant language
Java
Stars
564
Forks
140
Avg merge
36m
Merged PRs (30d)
2

Description

### Search before asking

- [x] I have searched the existing [issues](https://github.com/arextest/arex-agent-java/issues) before asking.

### AREX Test Service

AREX Java Agent (arextest/arex-agent-java)

### Current Behavior

在 TypeUtil.mapToString 方法中,逻辑会遍历 Map 的 entries,但仅处理第一个非空 value(由于 break; 语句),并用其类型来生成类型字符串。这假设 Map 中的所有值都是同质的(相同类型)。然而,对于 Map 中包含异构值(例如混合 Long 和 String)的场景,这会导致类型推断错误,在回放(replay)期间的反序列化失败。

### Expected Behavior

方法应该:

遍历所有 entries 并处理异构类型(例如生成联合类型字符串,或使用更灵活的表示如 java.lang.Object)。
或者,在文档中说明此限制,并警告用户确保 Map 中的值类型一致。
理想情况下,支持异构 Map 以避免反序列化错误。

### Steps To Reproduce

创建一个包含异构值的 Map,例如:JavaMap testMap = new HashMap<>();
testMap.put("key1", 123L); // Long 类型
testMap.put("key2", "hello"); // String 类型
在 AREX 的录制/回放场景中使用这个 Map(例如作为 Dubbo 服务的请求体)。
在录制阶段,mapToString 生成的类型字符串仅基于第一个非空值(例如,如果 "key1" 先遍历,则类型为 java.lang.Long)。
在回放阶段,反序列化时尝试将该类型应用于所有值,导致类型不匹配的值失败(例如,无法将 String 转换为 Long),抛出如 ClassCastException 的异常。

### Anything else

_No response_

### Are you willing to submit a pull request to fix on your own?

- [ ] Yes I am willing to submit a pull request on my own!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at TypeUtil.mapToString and reproduce the issue with a Map containing Long and String values in a Dubbo request body. Trace how the generated type string is used during replay deserialization; done means heterogeneous values replay without a type mismatch or conversion failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.