Fix for Hornetq-988

See https://issues.jboss.org/browse/HORNETQ-988.

I added a null check to prevent the nullpointer exception. The Jira has the test case attached to it.