Check result of dynamic_cast<> for null before dereferencing.
Fixes compilation warnings seen with gcc11.
GitLab jobs artifacts no longer stored forever as of Monday, November 4th 08:30h. Further information under https://cern.ch/otg0152576
Fixes compilation warnings seen with gcc11.