apache / apache/fory

Access ordered LinkedHashMap not preserved following deserialisation.

Open
#3,965 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.5k
Forks
443
Avg merge
6h 3m
Merged PRs (30d)
74

Description

### Search before asking

- [x] I had searched in the [issues](https://github.com/apache/fory/issues) and found no similar issues.

### Version

A serialised LinkedHashMap that was constructed to use access order (as opposed to insertion order), will lose this characteristic following deserialisation.

### Component(s)

Java

### Minimal reproduce step

```java
Fory fory = Fory.builder().withLanguage(Language.JAVA).build();
LinkedHashMap map = new LinkedHashMap<>(16, 0.75, true);
map.put(1, 1);
map.put(2, ");
map.put(3, 3);
map.put(4, 4);
LinkedHashMap deserialised = (LinkedHashMap) fory.deserialize(fory.serialize(map));

// This passes, as expected
assertEquals(map, deserialised);

// Modify access order
assertEquals(2, map.get(2));
assertEquals(4, map.get(4));
assertEquals(1, map.get(1));
assertEquals(3, map.get(3));

assertEquals(2, deserialised.get(2));
assertEquals(4, deserialised.get(4));
assertEquals(1, deserialised.get(1));
assertEquals(3, deserialised.get(3));

// This fails, since access order was not preserved
assertEquals(deserialised.values().iterator().next(), map.values().iterator().next());
```

### What did you expect to see?

The last assertion should have succeeded (as it would when following Java serialization).

### What did you see instead?

The last assertion fails.

### Anything Else?

_No response_

### Are you willing to submit a PR?

- [ ] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Start by running the minimal Java reproduction with Fory.builder().withLanguage(Language.JAVA), then trace the LinkedHashMap serialization and deserialization path. Done means a deserialized access-ordered LinkedHashMap changes iteration order identically after the same get calls, so the final assertion passes.

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
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.