Skip to content

COMPATIBLE mode silently drops contents of unregistered Map/Collection implementations #3621

@drse

Description

@drse

Search before asking

  • I had searched in the issues and found no similar issues.

Version

0.17.0

Component(s)

Java, Eclipse Collections

Minimal reproduce step

Tested with Eclipse Collections' UnifiedMap (any non-java.util Map impl should reproduce):

import org.apache.fory.Fory;
import org.apache.fory.config.CompatibleMode;
import org.apache.fory.config.Language;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.impl.map.mutable.UnifiedMap;

public class Holder {
    public MutableMap<String, String> data = new UnifiedMap<>();
}

Fory fory = Fory.builder()
    .withLanguage(Language.JAVA)
    .withCompatibleMode(CompatibleMode.COMPATIBLE)
    .requireClassRegistration(false)
    .build();

Holder h = new Holder();
h.data.put("k", "v");

byte[] bytes = fory.serialize(h);   // entry is written to the buffer
Holder out = (Holder) fory.deserialize(bytes);

System.out.println(out.data.getClass()); // class ...UnifiedMap
System.out.println(out.data.size());     // 0  ← silent loss
  • CompatibleMode.SCHEMA_CONSISTENT (with the class registered) → entry survives.
  • Field typed as java.util.LinkedHashMap (still COMPATIBLE) → entry survives.
  • Registering a CustomMapSerializer<UnifiedMap> per the custom-serializers
    guide
    → entry survives.

What did you expect to see?

One of:

  1. COMPATIBLE-mode generic dispatch routes unknown Map / Collection implementations through MapSerializer / CollectionSerializer so entries survive without
    explicit registration.
  2. COMPATIBLE-mode throws on encountering a Map / Collection impl it cannot fully round-trip, so the failure is loud at the boundary.

What did you see instead?

Silent partial deserialization. Empty collection created, no exceptions thrown.

Anything Else?

I think the default silent behavior is probably correct for most types, but for known collection types, the default behavior should probably be to throw to avoid silent corruption. At least that's my default expectation for collection types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions