From a8b42c26b615794f422c67ac205b3ed13782c89d Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Tue, 14 Jun 2016 11:35:25 -0400 Subject: [PATCH] NIFI-2006 fixed NPE in PersistentProvenanceRepository Fixed NPE in PersistentProvenanceRepository caused by attribute value being null added test This closes #528 --- .../nifi/provenance/PersistentProvenanceRepository.java | 8 +++----- .../provenance/TestPersistentProvenanceRepository.java | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/PersistentProvenanceRepository.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/PersistentProvenanceRepository.java index 0c830a7554..f91f6a4472 100644 --- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/PersistentProvenanceRepository.java +++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/PersistentProvenanceRepository.java @@ -1786,11 +1786,9 @@ public class PersistentProvenanceRepository implements ProvenanceEventRepository private Map truncateAttributes(final Map original) { final Map truncatedAttrs = new HashMap<>(); for (final Map.Entry entry : original.entrySet()) { - if (entry.getValue().length() > maxAttributeChars) { - truncatedAttrs.put(entry.getKey(), entry.getValue().substring(0, maxAttributeChars)); - } else { - truncatedAttrs.put(entry.getKey(), entry.getValue()); - } + String value = entry.getValue() != null && entry.getValue().length() > this.maxAttributeChars + ? entry.getValue().substring(0, this.maxAttributeChars) : entry.getValue(); + truncatedAttrs.put(entry.getKey(), value); } return truncatedAttrs; } diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestPersistentProvenanceRepository.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestPersistentProvenanceRepository.java index 4a5c08c4a6..3238d972c7 100644 --- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestPersistentProvenanceRepository.java +++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/java/org/apache/nifi/provenance/TestPersistentProvenanceRepository.java @@ -1225,6 +1225,7 @@ public class TestPersistentProvenanceRepository { final Map attributes = new HashMap<>(); attributes.put("75chars", "123456789012345678901234567890123456789012345678901234567890123456789012345"); + attributes.put("nullChar", null); final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder(); builder.setEventTime(System.currentTimeMillis());