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.
Attempting to use a
ListLexicoderto encode an empty list yields anArrayIndexOutOfBoundsExceptiondue to the following line inByteUtils.concat: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
SequenceLexicoderto distinguish it from the existingListLexicodername) 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 toByteUtils.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.