Avoid creating a NPE when closing

This is a performance optimization and improved logging so it doesn't hide problems in the future.

Closes #20176
This commit is contained in:
Alexander Schwartz 2023-05-05 12:53:31 +02:00 committed by Michal Hajas
parent 0f481da77f
commit 754aac2f4e

View file

@ -471,9 +471,11 @@ public class DefaultKeycloakSession implements KeycloakSession {
try {
Consumer<? super Provider> safeClose = p -> {
try {
p.close();
if (p != null) {
p.close();
}
} catch (Exception e) {
// Ignore exception
LOG.warnf(e, "Unable to close provider %s", p.getClass().getName());
}
};
providers.values().forEach(safeClose);