fix(search): treat null sender.lastName as empty in sort key

A sender with lastName=null produced sort key "null Bob" which sorted
before names starting with lowercase letters (n < s, t, u, v...).
Now returns "" for null lastName, which the comparator places at end.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-06 16:39:30 +02:00
parent 1c1ab0c72a
commit 972048d57d
2 changed files with 26 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@@ -327,7 +328,8 @@ public class DocumentService {
return documents.stream()
.sorted(Comparator.comparing(doc -> {
Person s = doc.getSender();
return s != null ? s.getLastName() + " " + s.getFirstName() : "";
if (s == null || s.getLastName() == null) return "";
return s.getLastName() + " " + Objects.toString(s.getFirstName(), "");
}, nullSafeComparator))
.toList();
}