add null object protection to build stream writer