Fix and test for USERGRID-18

Fix NPE when connected entity doesn't exist.