NIFI-2006 fixed NPE in PersistentProvenanceRepository

Fixed NPE in PersistentProvenanceRepository caused by attribute value being null
added test

This closes #528
This commit is contained in:
Oleg Zhurakousky 2016-06-14 11:35:25 -04:00 committed by jpercivall
parent 8b0c5a4911
commit a8b42c26b6
2 changed files with 4 additions and 5 deletions

View File

@ -1786,11 +1786,9 @@ public class PersistentProvenanceRepository implements ProvenanceEventRepository
private Map<String, String> truncateAttributes(final Map<String, String> original) {
final Map<String, String> truncatedAttrs = new HashMap<>();
for (final Map.Entry<String, String> 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;
}

View File

@ -1225,6 +1225,7 @@ public class TestPersistentProvenanceRepository {
final Map<String, String> attributes = new HashMap<>();
attributes.put("75chars", "123456789012345678901234567890123456789012345678901234567890123456789012345");
attributes.put("nullChar", null);
final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder();
builder.setEventTime(System.currentTimeMillis());