Skip to content

The accessOrder field in LinkedHashMap is not deserialized correctly. #1157

@leonchen83

Description

@leonchen83

Describe the bug
Since we set accessOrder to true during serialization, we expect the output order after deserialization to be a, b. However, due to the fact that the accessOrder field is not correctly deserialized, the actual output is b, a.

To Reproduce

public static void main(String[] args) {
    Kryo kryo = new Kryo();
    kryo.setReferences(true);
    kryo.setRegistrationRequired(true);
    kryo.register(LinkedHashMap.class);
    final Output output = new UnsafeOutput(512, 10240);
    
    LinkedHashMap<String, String> map = new LinkedHashMap<>(10, 0.85f, true);
    map.put("a", "a");
    map.put("b", "b");
    
    map.get("b");
    map.get("a");
    
    kryo.writeClassAndObject(output, map);
    LinkedHashMap<String, String> map1 = (LinkedHashMap) kryo.readClassAndObject(new UnsafeInput(output.toBytes()));
    
    map.get("a");
    map.get("b");
    
    for (String key : map1.keySet()) {
        System.out.println(key);
    }
}

Environment:

  • OS: windows11
  • JDK Version: 21
  • Kryo Version: 5.6.2

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions