Added a protection for possible null pointers

This pull request is to fulfill the following Jira issue:
https://its.cern.ch/jira/browse/CMSTRACK-6