From 24a83fc24f438e6dd928495864f4d32897133612 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Mon, 22 Apr 2024 11:39:44 +0200 Subject: [PATCH] avoid NPEs in common Oaf merge utilities --- .../java/eu/dnetlib/dhp/schema/oaf/utils/MergeUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/MergeUtils.java b/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/MergeUtils.java index c95c31c51..62b9731dc 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/MergeUtils.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/MergeUtils.java @@ -270,8 +270,9 @@ public class MergeUtils { } HashMap values = new HashMap<>(); - left.forEach(kv -> values.put(kv.getKey(), kv)); - right.forEach(kv -> values.putIfAbsent(kv.getKey(), kv)); + + Optional.ofNullable(left).ifPresent(l -> l.forEach(kv -> values.put(kv.getKey(), kv))); + Optional.ofNullable(right).ifPresent(r -> r.forEach(kv -> values.putIfAbsent(kv.getKey(), kv))); return new ArrayList<>(values.values()); }