Repository: camel
Updated Branches:
  refs/heads/master 3743c2256 -> 94f621d15


CAMEL-11609:thread-safety if headers get modified on the fly


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/94f621d1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/94f621d1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/94f621d1

Branch: refs/heads/master
Commit: 94f621d153ba2db4925950e9fd231f0578fa13a6
Parents: 3743c22
Author: Daniel Baldes <dan...@baldes.name>
Authored: Tue Aug 1 11:24:46 2017 +0200
Committer: Andrea Cosentino <anco...@gmail.com>
Committed: Tue Aug 1 13:25:00 2017 +0200

----------------------------------------------------------------------
 .../camel/dataformat/univocity/Marshaller.java  | 36 ++++++++++++++------
 1 file changed, 25 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/94f621d1/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/Marshaller.java
----------------------------------------------------------------------
diff --git 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/Marshaller.java
 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/Marshaller.java
index 5c113cb..1161559 100644
--- 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/Marshaller.java
+++ 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/Marshaller.java
@@ -16,17 +16,18 @@
  */
 package org.apache.camel.dataformat.univocity;
 
+import static org.apache.camel.util.ExchangeHelper.convertToMandatoryType;
+import static org.apache.camel.util.ExchangeHelper.convertToType;
+
 import java.util.Arrays;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 
-import com.univocity.parsers.common.AbstractWriter;
 import org.apache.camel.Exchange;
 import org.apache.camel.NoTypeConversionAvailableException;
 
-import static org.apache.camel.util.ExchangeHelper.convertToMandatoryType;
-import static org.apache.camel.util.ExchangeHelper.convertToType;
+import com.univocity.parsers.common.AbstractWriter;
 
 /**
  * This class marshalls the exchange body using an uniVocity writer. It can 
automatically generates headers and keep
@@ -85,16 +86,29 @@ final class Marshaller<W extends AbstractWriter<?>> {
     private void writeRow(Exchange exchange, Object row, W writer) throws 
NoTypeConversionAvailableException {
         Map<?, ?> map = convertToMandatoryType(exchange, Map.class, row);
         if (adaptHeaders) {
-            for (Object key : map.keySet()) {
-                headers.add(convertToMandatoryType(exchange, String.class, 
key));
+            synchronized (headers) {
+                for (Object key : map.keySet()) {
+                    headers.add(convertToMandatoryType(exchange, String.class, 
key));
+                }
+                writeRow(map, writer);
             }
+        } else {
+            writeRow(map, writer);
         }
+    }
 
-        Object[] values = new Object[headers.size()];
-        int index = 0;
-        for (String header : headers) {
-            values[index++] = map.get(header);
-        }
-        writer.writeRow(values);
+    /**
+     * Writes the given map as row.
+     * 
+     * @param map row values by header
+     * @param writer uniVocity writer to use
+     */
+    private void writeRow(Map<?, ?> map, W writer) {
+      Object[] values = new Object[headers.size()];
+      int index = 0;
+      for (String header : headers) {
+          values[index++] = map.get(header);
+      }
+      writer.writeRow(values);
     }
 }

Reply via email to