This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new aea5821de7 ISIS-3084: commons: make _List concat utils null-safe
aea5821de7 is described below

commit aea5821de7070759a956bbd367d907f39d936109
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Thu Jun 30 10:39:26 2022 +0200

    ISIS-3084: commons: make _List concat utils null-safe
---
 .../isis/commons/internal/collections/_Lists.java   | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git 
a/commons/src/main/java/org/apache/isis/commons/internal/collections/_Lists.java
 
b/commons/src/main/java/org/apache/isis/commons/internal/collections/_Lists.java
index 2d5ed27a6d..56ecdeb6ab 100644
--- 
a/commons/src/main/java/org/apache/isis/commons/internal/collections/_Lists.java
+++ 
b/commons/src/main/java/org/apache/isis/commons/internal/collections/_Lists.java
@@ -77,7 +77,10 @@ public final class _Lists {
      * Returns an unmodifiable list containing all elements from given list
      * and the specified element.
      */
-    public static <T> List<T> append(final List<T> list, final T element) {
+    public static <T> List<T> append(final @Nullable List<T> list, final 
@Nullable T element) {
+        if(_NullSafe.isEmpty(list)) {
+            return Collections.singletonList(element);
+        }
         val resultList = new ArrayList<T>(list.size() + 1);
         resultList.addAll(list);
         resultList.add(element);
@@ -88,7 +91,21 @@ public final class _Lists {
      * Returns an unmodifiable list containing all elements from given lists
      * list1 and list2.
      */
-    public static <T> List<T> concat(final List<T> list1, final List<T> list2) 
{
+    public static <T> List<T> concat(final @Nullable List<T> list1, final 
@Nullable List<T> list2) {
+        val isEmpty1 = _NullSafe.isEmpty(list1);
+        val isEmpty2 = _NullSafe.isEmpty(list2);
+
+        if(isEmpty1) {
+            return isEmpty2
+                    ? Collections.emptyList()
+                    : Collections.unmodifiableList(new ArrayList<T>(list2));
+        }
+
+        if(isEmpty2) {
+            // at this point list1 is not empty
+            return Collections.unmodifiableList(new ArrayList<T>(list1));
+        }
+
         val resultList = new ArrayList<T>(list1.size() + list2.size());
         resultList.addAll(list1);
         resultList.addAll(list2);

Reply via email to