Added null check in generateStackTrace

The stack returned can be null which can cause an error when stack.map
is performed.