Return-Path: X-Original-To: apmail-camel-issues-archive@minotaur.apache.org Delivered-To: apmail-camel-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0534110512 for ; Fri, 17 Jan 2014 20:08:26 +0000 (UTC) Received: (qmail 40907 invoked by uid 500); 17 Jan 2014 20:08:25 -0000 Delivered-To: apmail-camel-issues-archive@camel.apache.org Received: (qmail 40762 invoked by uid 500); 17 Jan 2014 20:08:23 -0000 Mailing-List: contact issues-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list issues@camel.apache.org Received: (qmail 40568 invoked by uid 99); 17 Jan 2014 20:08:22 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Jan 2014 20:08:22 +0000 Date: Fri, 17 Jan 2014 20:08:22 +0000 (UTC) From: "John Douglass (JIRA)" To: issues@camel.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (CAMEL-7142) CsvDataFormat unmarshal overwrites delimiter in static CSVStrategy strategies MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 John Douglass created CAMEL-7142: ------------------------------------ Summary: CsvDataFormat unmarshal overwrites delimiter in static CSVStrategy strategies Key: CAMEL-7142 URL: https://issues.apache.org/jira/browse/CAMEL-7142 Project: Camel Issue Type: Bug Components: camel-csv Affects Versions: 2.12.2 Reporter: John Douglass Priority: Minor The unmarshal function in CsvDataFormat contains the following line: {code} strategy.setDelimiter(config.getDelimiter()); {code} This can cause problems when multiple CsvDataFormats are used which rely on the default CSVStrategy or one of the other static CSVStrategy objects. Here is sample code to demonstrate the problem: {code} final CsvDataFormat csv = new CsvDataFormat(); final CsvDataFormat tsv = new CsvDataFormat(); tsv.setDelimiter("\t"); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("file:///tmp/?include=.*.csv") .unmarshal(csv) .process(new MyProcessor()); from("file:///tmp/?include=.*.tsv") .unmarshal(tsv) .process(new MyProcessor()); } }); {code} Running the code above with several files with 2 lines, 9 columns per line and comma or tab delimiters returns the following (the exact values may be different from run to run): {code} File: 0.tsv, lines: 2 Line 1 columns: 9 Line 2 columns: 9 File: 0.csv, lines: 2 Line 1 columns: 1 Line 2 columns: 1 File: 1.csv, lines: 2 Line 1 columns: 2 Line 2 columns: 1 File: 1.tsv, lines: 2 Line 1 columns: 9 Line 2 columns: 9 {code} These should all show 9 columns. Adding the following lines corrects the problem, because each DataFormat has its own CSVStrategy: {code} csv.setStrategy(new CSVStrategy(',', '"', '#')); tsv.setStrategy(new CSVStrategy('\t', '"', '#')); {code} The suggested fix would be for the CsvDataFormat to have its own copy of its CSVStrategy instead of using what amounts to a pointer to another CSVStrategy. Perhaps setStrategy should be changed to do that. This is tedious because CSVStrategy has no copy constructor and has many properties, but would be a defensive way to do it. Note also that the example at http://camel.apache.org/csv.html under "Unmarshalling with a pipe as delimiter" actually alters the CSVStrategy.DEFAULT_STRATEGY, so any subsequent CsvDataFormat objects created would have a pipe as the delimiter. -- This message was sent by Atlassian JIRA (v6.1.5#6160)