From 9a38a1ba4b740cf17b9e94977b8583523c9c9d7b Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Fri, 3 Apr 2020 18:50:52 +0200 Subject: [PATCH] Re-fix NPEs in notifications (cherry picked from commit 8162efdf4d1cc4783a3f600025f4ff4797f772ee) --- .../impl/events/ModelEventImpl.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java index 7acc5a43ad8..94435537e6a 100644 --- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java +++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java @@ -236,14 +236,16 @@ public boolean hasContentToShow(boolean watchAuxiliaryAttributes) { ObjectDelta summarizedDelta; try { summarizedDelta = getSummarizedFocusDeltas(); - if (!ObjectDelta.isModify(summarizedDelta)) { + if (summarizedDelta == null) { + return false; + } else if (summarizedDelta.isAdd() || summarizedDelta.isDelete()) { return true; - } else if (!getTextFormatter().containsVisibleModifiedItems(summarizedDelta.getModifications(), + } else if (getTextFormatter().containsVisibleModifiedItems(summarizedDelta.getModifications(), false, watchAuxiliaryAttributes)) { + return true; + } else { LOGGER.trace("No relevant attributes in modify delta (watchAux={})", watchAuxiliaryAttributes); return false; - } else { - return true; } } catch (Throwable t) { LoggingUtils.logUnexpectedException(LOGGER, "Unable to check if there's content to show; focus context = {}", t, focusContext.debugDump()); @@ -255,9 +257,11 @@ public boolean hasContentToShow(boolean watchAuxiliaryAttributes) { public String getContentAsFormattedList(boolean showAuxiliaryAttributes) { try { ObjectDelta summarizedDelta = getSummarizedFocusDeltas(); - if (ObjectDelta.isAdd(summarizedDelta)) { + if (summarizedDelta == null) { + return ""; // should not happen + } else if (summarizedDelta.isAdd()) { return getTextFormatter().formatObject(summarizedDelta.getObjectToAdd(), false, showAuxiliaryAttributes); - } else if (ObjectDelta.isModify(summarizedDelta)) { + } else if (summarizedDelta.isModify()) { ModelElementContext focusContext = modelContext.getFocusContext(); return getTextFormatter().formatObjectModificationDelta(summarizedDelta, false, showAuxiliaryAttributes, focusContext.getObjectOld(), focusContext.getObjectNew());