Fixed issues reported by coverity NPEs, unwritten field access and self assignment

Signed-off-by: Koushik Das <koushik@apache.org>