diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
index 321dfc4..29de356 100644
--- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
+++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
@@ -192,7 +192,9 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont
    */
   public function referencedEntities() {
     $referenced_entities = parent::referencedEntities();
-    $referenced_entities[] = $this->getCommentedEntity();
+    if ($this->getCommentedEntityId()) {
+      $referenced_entities[] = $this->getCommentedEntity();
+    }
     return $referenced_entities;
   }
 
