camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Douglass (JIRA)" <>
Subject [jira] [Created] (CAMEL-7142) CsvDataFormat unmarshal overwrites delimiter in static CSVStrategy strategies
Date Fri, 17 Jan 2014 20:08:22 GMT
John Douglass created CAMEL-7142:

             Summary: CsvDataFormat unmarshal overwrites delimiter in static CSVStrategy strategies
                 Key: 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:


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:
final CsvDataFormat csv = new CsvDataFormat();
final CsvDataFormat tsv = new CsvDataFormat();

context.addRoutes(new RouteBuilder() {
    public void configure() throws Exception {
                .process(new MyProcessor());
                .process(new MyProcessor());

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):

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

These should all show 9 columns.

Adding the following lines corrects the problem, because each DataFormat has its own CSVStrategy:

csv.setStrategy(new CSVStrategy(',', '"', '#'));
tsv.setStrategy(new CSVStrategy('\t', '"', '#'));

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 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

View raw message