add some null checks

This commit is contained in:
David Renshaw 2014-09-04 15:25:56 -04:00
parent e65b934db0
commit 3c6d02ecdd
2 changed files with 20 additions and 8 deletions

View file

@ -29,17 +29,27 @@ public final class PointerReader {
}
public StructReader getStruct() {
return WireHelpers.readStructPointer(this.segment,
this.pointer,
this.nestingLimit);
if (this.segment == null) {
return WireHelpers.readStructPointer(SegmentReader.EMPTY, 0, this.nestingLimit);
} else {
return WireHelpers.readStructPointer(this.segment,
this.pointer,
this.nestingLimit);
}
}
public ListReader getList(byte expectedElementSize) {
// TODO check nullness
return WireHelpers.readListPointer(this.segment,
this.pointer,
expectedElementSize,
this.nestingLimit);
if (this.segment == null) {
return WireHelpers.readListPointer(SegmentReader.EMPTY,
0,
expectedElementSize,
this.nestingLimit);
} else {
return WireHelpers.readListPointer(this.segment,
this.pointer,
expectedElementSize,
this.nestingLimit);
}
}
public Text.Reader getText() {

View file

@ -13,4 +13,6 @@ public class SegmentReader {
this.buffer = buffer;
this.arena = arena;
}
public static final SegmentReader EMPTY = new SegmentReader(ByteBuffer.allocate(8), null);
}