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

Open
#620 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start at TypeUtil.mapToString and reproduce the issue with a Map<String, Object> 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.

Description

bug :lady_beetle:
Search before asking
  • I have searched the existing issues before asking.
AREX Test Service

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

Current Behavior

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

Expected Behavior

方法应该:

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

Steps To Reproduce

创建一个包含异构值的 Map<String, Object>,例如:JavaMap<String, Object> 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!
Dominant language
Java
Stars
566
Forks
141
Avg merge
36m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from arextest/arex-agent-java

All issues in arextest/arex-agent-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.