Skip to content

ListLexicoder does not support empty lists #1252

@reggert

Description

@reggert

Attempting to use a ListLexicoder to encode an empty list yields an ArrayIndexOutOfBoundsException due to the following line in ByteUtils.concat:

byte[] ret = new byte[len + fields.length - 1];

Unfortunately, any attempt to resolve this is not likely to be backwards compatible with existing data encoded using the current implementation.

I suggest adding a separate class (perhaps called something like SequenceLexicoder to distinguish it from the existing ListLexicoder name) the is able to handle possibly-empty lists and deprecating the existing class (or at least clearly documenting that it is not appropriate to use in cases where the list may be empty). Probably the best solution in terms of implementation is to append an empty element to the end of the list that gets passed to ByteUtils.concat. In this case, an empty list will be encoded as an empty value, and a list containing exactly one empty element (e.g., a list containing only an empty string) will be encoded as a single delimiter byte.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions