diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
index db194b5485..b0b94b8dbb 100644
--- a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
+++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
@@ -167,7 +167,7 @@ public function applyDefaultValue($notify = TRUE) {
    * {@inheritdoc}
    */
   public function getIterator() {
-    return isset($this->entity) ? $this->entity->getIterator() : new \ArrayIterator([]);
+    return $this->entity instanceof \IteratorAggregate ? $this->entity->getIterator() : new \ArrayIterator([]);
   }
 
 }
