The following pattern triggers the error:
writeObject(comparator)
writeObject(map)
This is because the map is added to the instance cache BEFORE the nested comparator when writing, resulting in a sequence that is reversed from what the reading side expects. The solution is for the reader to add a placeholder and later fill it.