From 3dd548e807c80749a99f83e18857cab879cd9c21 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Wed, 19 Sep 2018 16:17:29 -0400 Subject: [PATCH] NIFI-5609: Fixed NullPointer when attempting to view status history for a component that has not yet run Signed-off-by: Matthew Burgess This closes #3012 --- .../VolatileComponentStatusRepository.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/VolatileComponentStatusRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/VolatileComponentStatusRepository.java index 5336d17fbb..b2802142c3 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/VolatileComponentStatusRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/VolatileComponentStatusRepository.java @@ -27,6 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -166,13 +167,34 @@ public class VolatileComponentStatusRepository implements ComponentStatusReposit private synchronized StatusHistory getStatusHistory(final String componentId, final boolean includeCounters, final Set> defaultMetricDescriptors) { final ComponentStatusHistory history = componentStatusHistories.get(componentId); if (history == null) { - return null; + return createEmptyStatusHistory(); } final List dates = timestamps.asList(); return history.toStatusHistory(dates, includeCounters, defaultMetricDescriptors); } + private StatusHistory createEmptyStatusHistory() { + final Date dateGenerated = new Date(); + + return new StatusHistory() { + @Override + public Date getDateGenerated() { + return dateGenerated; + } + + @Override + public Map getComponentDetails() { + return Collections.emptyMap(); + } + + @Override + public List getStatusSnapshots() { + return Collections.emptyList(); + } + }; + } + @Override public GarbageCollectionHistory getGarbageCollectionHistory(final Date start, final Date end) {