Add control to avoid NPE (see #10402) (rebased onto develop)



This is the same as gh-868 but rebased onto develop.

----

Add control to avoid NPE
see https://trac.openmicroscopy.org.uk/ome/ticket/10402