From d3a4bef9a4e92861a1cbee3c0477e361d7cc760d Mon Sep 17 00:00:00 2001 From: Stefan Guilhen Date: Tue, 31 Mar 2020 12:22:05 -0300 Subject: [PATCH] [KEYCLOAK-8789] Fix getAttribute(String name) implementations so they never return null - user adapter classes were violating the UserModel contract as the javadoc for the method states that null must never be returned --- .../java/org/keycloak/storage/adapter/AbstractUserAdapter.java | 2 +- .../storage/adapter/AbstractUserAdapterFederatedStorage.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapter.java b/server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapter.java index ae8eabe680..7dbeeca549 100644 --- a/server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapter.java +++ b/server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapter.java @@ -323,7 +323,7 @@ public abstract class AbstractUserAdapter implements UserModel { @Override public List getAttribute(String name) { - return null; + return Collections.emptyList(); } @Override diff --git a/server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java b/server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java index c14f981fc9..747f9a8d28 100644 --- a/server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java +++ b/server-spi/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java @@ -364,7 +364,8 @@ public abstract class AbstractUserAdapterFederatedStorage implements UserModel { @Override public List getAttribute(String name) { - return getFederatedStorage().getAttributes(realm, this.getId()).get(name); + List result = getFederatedStorage().getAttributes(realm, this.getId()).get(name); + return (result == null) ? Collections.emptyList() : result; } @Override