From 40058ca86af6e1101265ffc57837e2ee7c5060b6 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Sat, 20 Jul 2024 18:03:29 +0200 Subject: [PATCH] Fix that profile page would have an NPE when e-mail is missing --- .../gartenplus/ui/content/admin/ProfilePage.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/penguineering/gartenplus/ui/content/admin/ProfilePage.java b/src/main/java/com/penguineering/gartenplus/ui/content/admin/ProfilePage.java index 4078ba4..4471bfb 100644 --- a/src/main/java/com/penguineering/gartenplus/ui/content/admin/ProfilePage.java +++ b/src/main/java/com/penguineering/gartenplus/ui/content/admin/ProfilePage.java @@ -15,10 +15,7 @@ import jakarta.annotation.security.PermitAll; import org.springframework.beans.factory.annotation.Qualifier; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.function.Supplier; @Route(value = "profile", layout = AdminLayout.class) @@ -50,9 +47,9 @@ public ProfilePage(@Qualifier("user") Supplier currentUser, List> items = new ArrayList<>(); userOpt.ifPresent(userDTO -> { - items.add(Map.entry("Name", userDTO.displayName())); - items.add(Map.entry("E-Mail-Adresse", userDTO.email())); - items.add(Map.entry("Avatar-URL", userDTO.avatarUrl().toASCIIString())); + items.add(Map.entry("Name", Objects.requireNonNullElse(userDTO.displayName(), ""))); + items.add(Map.entry("E-Mail-Adresse", Objects.requireNonNullElse(userDTO.email(), ""))); + items.add(Map.entry("Avatar-URL", userDTO.avatarUrl() == null ? "" : userDTO.avatarUrl().toASCIIString())); }); grid.setItems(items);