[BUG #8433] Add additional if statement to prevent exceptions
(cherry picked from commit 853df95aa08e3c3780a0a0d04431b33281e8da1f)