Fixing NPE and ArrayIndexOutOfBounds exceptions

We are seeing NullPointerExceptions and ArrayIndexOutOfBounds Exceptions.  There are times where files are not generated and other things like.

Thanks.