From c822b4010b6eb5f49d5949b1af786460ad89f0d7 Mon Sep 17 00:00:00 2001 From: Martin Kanis Date: Wed, 17 Apr 2024 09:02:22 +0200 Subject: [PATCH] NPE in user-storage-jpa when searching by empty string Closes #546 Signed-off-by: Martin Kanis (cherry picked from commit ac868332c95457b408a76853dde7012c51856c2a) --- .../quickstart/storage/user/MyUserStorageProvider.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extension/user-storage-jpa/src/main/java/org/keycloak/quickstart/storage/user/MyUserStorageProvider.java b/extension/user-storage-jpa/src/main/java/org/keycloak/quickstart/storage/user/MyUserStorageProvider.java index d13748daa..5d2ed96e2 100644 --- a/extension/user-storage-jpa/src/main/java/org/keycloak/quickstart/storage/user/MyUserStorageProvider.java +++ b/extension/user-storage-jpa/src/main/java/org/keycloak/quickstart/storage/user/MyUserStorageProvider.java @@ -229,7 +229,8 @@ public int getUsersCount(RealmModel realm) { public Stream searchForUserStream(RealmModel realm, Map params, Integer firstResult, Integer maxResults) { String search = params.get(UserModel.SEARCH); TypedQuery query = em.createNamedQuery("searchForUser", UserEntity.class); - query.setParameter("search", "%" + search.toLowerCase() + "%"); + String lower = search != null ? search.toLowerCase() : ""; + query.setParameter("search", "%" + lower + "%"); if (firstResult != null) { query.setFirstResult(firstResult); }