diff --git a/flag_lists.module b/flag_lists.module
index cd81104..1da0c9a 100644
--- a/flag_lists.module
+++ b/flag_lists.module
@@ -240,7 +240,7 @@ function flag_lists_flag_action_access($action, FlagInterface $flag, AccountInte
   $flagListsService = Drupal::service('flaglists');
   $flagLists = $flagListsService->getAllFlaggingCollections();
   foreach ($flagLists as $flagList) {
-    if ($flag->id() == $flagList->getRelatedFlag()->id()) {
+    if ($flagList->getRelatedFlag() && $flag->id() == $flagList->getRelatedFlag()->id()) {
       if ($flagList->getBaseFlag()->isGlobal()) {
         // The flag list is global.
         return AccessResult::allowedIfHasPermission($account,
