You make a good point.The one with fewer nulls is going to sort before the one with more nulls, which isn't what we want. Does this test succeed?

We need to invert the byte that counts the nulls: you can use byte nullCountByte = SortOrder.invert(nullCountByte); Then it'll sort correctly. Sorry, I missed that before