From 0a58bc7ba7b4aa200aaeadd27aa461416af8c9ac Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Wed, 11 Jan 2023 14:44:14 +0100 Subject: [PATCH] [broker] prevent NPEs --- .../dhp/broker/oa/util/ConversionUtils.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/util/ConversionUtils.java b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/util/ConversionUtils.java index 9b5a5036d..4bf4d3341 100644 --- a/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/util/ConversionUtils.java +++ b/dhp-workflows/dhp-broker-events/src/main/java/eu/dnetlib/dhp/broker/oa/util/ConversionUtils.java @@ -128,13 +128,22 @@ public class ConversionUtils { protected static List allResultPids(final Result result) { final Map map = new HashMap<>(); - result.getPid().forEach(sp -> map.put(sp.getValue(), sp)); - result.getInstance().forEach(i -> { - i.getPid().forEach(sp -> map.put(sp.getValue(), sp)); - i.getAlternateIdentifier().forEach(sp -> map.put(sp.getValue(), sp)); - }); - final List pids = mappedList(map.values(), ConversionUtils::oafPidToBrokerPid); - return pids; + + if (result.getPid() != null) { + result.getPid().forEach(sp -> map.put(sp.getValue(), sp)); + } + + if (result.getInstance() != null) { + result.getInstance().forEach(i -> { + if (i.getPid() != null) { + i.getPid().forEach(sp -> map.put(sp.getValue(), sp)); + } + if (i.getAlternateIdentifier() != null) { + i.getAlternateIdentifier().forEach(sp -> map.put(sp.getValue(), sp)); + } + }); + } + return mappedList(map.values(), ConversionUtils::oafPidToBrokerPid); } public static String cleanOpenaireId(final String id) {