fix for bug USERGRID-22, ICLA - Malaka Mahanama

This is a fix for the bug: https://issues.apache.org/jira/browse/USERGRID-22
Three validations needed to be done to prevent the null pointer exception.