Skip to content

MapSerializer._orderEntries should check for null keys. #1411

@huxi

Description

@huxi
    protected Map<?,?> _orderEntries(Map<?,?> input)
    {
        // minor optimization: may already be sorted?
        if (input instanceof SortedMap<?,?>) {
            return input;
        }
        return new TreeMap<Object,Object>(input);
    }

should be changed to

    protected Map<?,?> _orderEntries(Map<?,?> input)
    {
        // minor optimization: may already be sorted?
        if (input instanceof SortedMap<?,?>) {
            return input;
        }
        // prevent NPE in TreeMap
        if (input.containsKey(null)) {
            return input;
        }
        return new TreeMap<Object,Object>(input);
    }

TreeMap will otherwise throw a NullPointerException.

This would mean that a Map is potentially serialized unsorted as a fallback even if ORDER_MAP_ENTRIES_BY_KEYS is active but I guess that's still better than exploding with an exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions