Problem/Motivation
Display modes are applicable at the entity type level, not the bundle level. And not all bundles have enabled corresponding display mode(s).
$form_display = $storage->load("$entity_type_id.$bundle.$mode");
So that $form_display could be NULL here, and furthermore, it's possible to set the object of EntityDisplayInterface to NULL, and this is where the bug existed.
Proposed resolution
Check NULL cases.
Comments
Comment #3
jungleComment #4
jungle