Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
Description
UnionListWriter.setPosition() is implemented as follows:
@Override public void setPosition(int index) { super.setPosition(index); startList(); }
It works fine, but if you run the following code:
MapVector parent = new MapVector("parent", allocator, null); ComplexWriter writer = new ComplexWriterImpl("root", parent); MapWriter rootWriter = writer.rootAsMap(); rootWriter.start(); rootWriter.bigInt("int").writeBigInt(0); rootWriter.list("list").startList(); rootWriter.list("list").bigInt().writeBigInt(0); rootWriter.list("list").endList(); rootWriter.end(); rootWriter.setPosition(1); rootWriter.start(); rootWriter.bigInt("int").writeBigInt(1); rootWriter.end(); rootWriter.setPosition(2); rootWriter.bigInt("int").writeBigInt(2); rootWriter.start(); rootWriter.list("list").startList(); rootWriter.list("list").bigInt().writeBigInt(2); rootWriter.list("list").endList(); rootWriter.end(); writer.setValueCount(3); for (int i = 0; i < 3; i++) { parent.getReader().setPosition(i); System.out.printf("%d: %s%n", i, parent.getReader().readObject()); }
You get:
0: {"root":{"int":0,"list":[0]}} 1: {"root":{"int":1,"list":[]}} 2: {"root":{"int":2,"list":[2]}}
Even though we didn't write anything in the 2nd row "list", it shows up as empty instead of null. I tracked the problem to UnionListWriter.setPosition() calling startList() which marks the row as not null even if we don't write anything to it.