map中两个key指向同一个对象,反序列化后一个key的value丢失。
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
*简要描述您碰到的问题。*
map中两个key指向同一个对象,反序列化后一个key的value丢失。
### 环境信息
*请填写以下信息:*
- OS信息: [e.g.:window10 16 GB]
- JDK信息: [e.g.:jdk 17.0.2]
- 版本信息:[e.g.:Fastjson2 2.0.52]
### 重现步骤
`public void testLinkHashMap() throws Exception {
FrameworkModel frameworkModel = new FrameworkModel();
Serialization serialization = frameworkModel.getExtensionLoader(Serialization.class).getExtension("fastjson2");
URL url = URL.valueOf("").setScopeModel(frameworkModel);
//LinkedHashMap>> data = lmReportSQService.getData(user, "73N", DateUtil.toDate("2024-08-01"));
LinkedHashMap>> data = new LinkedHashMap<>(2);
List> lists = new ArrayList<>();
Timestamp timestamp = new Timestamp(1724947200000l);
Map map = new HashMap<>();
map.put("correct_date", timestamp);
lists.add(map);
// write pojo, read pojo
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ObjectOutput objectOutput = serialization.serialize(url, outputStream);
for (Map item : lists) {
item.put("correct_date" + "_end", item.get("correct_date"));
}
data.put(Integer.valueOf(0), lists);
objectOutput.writeObject(data);
objectOutput.flushBuffer();
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url, inputStream);
LinkedHashMap>> readList = objectInput.readObject(LinkedHashMap.class);
System.out.println(readList);
}`
Contributor guide
Research direction
Start with the testLinkHashMap reproduction, especially the serialization.writeObject and deserialization.readObject calls. Run the example and inspect the round-trip result for the two map keys that reference the same Timestamp. Done means the deserialized LinkedHashMap retains both values instead of losing one.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100