From f0f664dbb573cc8c0d63154acd3546efadb50c84 Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Tue, 13 Jun 2023 18:08:14 +0200 Subject: [PATCH] Prevent NPE on close() if postInit() hasn't been called Closes #20977 --- .../java/org/keycloak/models/jpa/JpaRealmProviderFactory.java | 4 +++- .../storage/datastore/LegacyDatastoreProviderFactory.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProviderFactory.java b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProviderFactory.java index 1fdddd4e3b..7947b60877 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProviderFactory.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProviderFactory.java @@ -67,7 +67,9 @@ public class JpaRealmProviderFactory implements RealmProviderFactory, ProviderEv @Override public void close() { - onClose.run(); + if (onClose != null) { + onClose.run(); + } } @Override diff --git a/model/legacy-private/src/main/java/org/keycloak/storage/datastore/LegacyDatastoreProviderFactory.java b/model/legacy-private/src/main/java/org/keycloak/storage/datastore/LegacyDatastoreProviderFactory.java index 2f80ea1000..7e2ea943e7 100644 --- a/model/legacy-private/src/main/java/org/keycloak/storage/datastore/LegacyDatastoreProviderFactory.java +++ b/model/legacy-private/src/main/java/org/keycloak/storage/datastore/LegacyDatastoreProviderFactory.java @@ -66,7 +66,9 @@ public class LegacyDatastoreProviderFactory implements DatastoreProviderFactory, @Override public void close() { - onClose.run(); + if (onClose != null) { + onClose.run(); + } } @Override