From ab7940368a18e8d29d8fadcc435db8ae8b4ee001 Mon Sep 17 00:00:00 2001 From: Tony Kurc Date: Tue, 17 Nov 2015 22:16:24 -0500 Subject: [PATCH] NIFI-1187: Fixing issue of possible assigment reordering causing uninitalized values to be possibly returned Signed-off-by: Aldrin Piri --- .../couchbase/AbstractCouchbaseProcessor.java | 8 +++----- .../nifi/processors/flume/util/FlowFileEvent.java | 15 +++------------ 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/nifi-nar-bundles/nifi-couchbase-bundle/nifi-couchbase-processors/src/main/java/org/apache/nifi/processors/couchbase/AbstractCouchbaseProcessor.java b/nifi-nar-bundles/nifi-couchbase-bundle/nifi-couchbase-processors/src/main/java/org/apache/nifi/processors/couchbase/AbstractCouchbaseProcessor.java index 158caa1d67..ec0e9abca1 100644 --- a/nifi-nar-bundles/nifi-couchbase-bundle/nifi-couchbase-processors/src/main/java/org/apache/nifi/processors/couchbase/AbstractCouchbaseProcessor.java +++ b/nifi-nar-bundles/nifi-couchbase-bundle/nifi-couchbase-processors/src/main/java/org/apache/nifi/processors/couchbase/AbstractCouchbaseProcessor.java @@ -137,12 +137,10 @@ public abstract class AbstractCouchbaseProcessor extends AbstractProcessor { } private CouchbaseClusterControllerService getClusterService(final ProcessContext context) { - if (clusterService == null) { - synchronized (AbstractCouchbaseProcessor.class) { - if (clusterService == null) { - clusterService = context.getProperty(COUCHBASE_CLUSTER_SERVICE) + synchronized (AbstractCouchbaseProcessor.class) { + if (clusterService == null) { + clusterService = context.getProperty(COUCHBASE_CLUSTER_SERVICE) .asControllerService(CouchbaseClusterControllerService.class); - } } } diff --git a/nifi-nar-bundles/nifi-flume-bundle/nifi-flume-processors/src/main/java/org/apache/nifi/processors/flume/util/FlowFileEvent.java b/nifi-nar-bundles/nifi-flume-bundle/nifi-flume-processors/src/main/java/org/apache/nifi/processors/flume/util/FlowFileEvent.java index fdff203544..c552d4de29 100644 --- a/nifi-nar-bundles/nifi-flume-bundle/nifi-flume-processors/src/main/java/org/apache/nifi/processors/flume/util/FlowFileEvent.java +++ b/nifi-nar-bundles/nifi-flume-bundle/nifi-flume-processors/src/main/java/org/apache/nifi/processors/flume/util/FlowFileEvent.java @@ -59,12 +59,8 @@ public class FlowFileEvent implements Event { @Override public Map getHeaders() { - if (!headersLoaded) { - synchronized (headers) { - if (headersLoaded) { - return headers; - } - + synchronized (headers) { + if (!headersLoaded) { headers.putAll(flowFile.getAttributes()); headers.put(ENTRY_DATE_HEADER, Long.toString(flowFile.getEntryDate())); headers.put(ID_HEADER, Long.toString(flowFile.getId())); @@ -76,7 +72,6 @@ public class FlowFileEvent implements Event { } headers.put(LINEAGE_START_DATE_HEADER, Long.toString(flowFile.getLineageStartDate())); headers.put(SIZE_HEADER, Long.toString(flowFile.getSize())); - headersLoaded = true; } } @@ -94,11 +89,7 @@ public class FlowFileEvent implements Event { @Override public byte[] getBody() { - if (bodyLoaded) { - return body; - } - - synchronized (bodyLock ) { + synchronized (bodyLock) { if (!bodyLoaded) { if (flowFile.getSize() > Integer.MAX_VALUE) { throw new RuntimeException("Can't get body of Event because the backing FlowFile is too large (" + flowFile.getSize() + " bytes)");