Null pointer is assigned when there are no tacks associated with the jets in the Secondary Vertex and Jet Fitter algorithm. The element links are not set due to the failed cast on the nulls. When resetting the element links afterwards, this triggers errors.
The fix uses the handle's this case in a more proper way. It does not rely on cast any more to determine the algo. Instead it uses the algo name directly and checks whether it is null afterwards. In this way, even when there are no tracks associated with the jets, the default element link is created.