[ 
https://issues.apache.org/jira/browse/CAMEL-24167?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-24167.
---------------------------------
    Resolution: Fixed

> camel-csv - 'format' option (EXCEL, MYSQL, ...) is silently ignored (dead 
> guard), and mismatches commons-csv Predefined names
> -----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-24167
>                 URL: https://issues.apache.org/jira/browse/CAMEL-24167
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-csv
>            Reporter: Federico Mariani
>            Assignee: Federico Mariani
>            Priority: Major
>              Labels: ai-assisted-review, dataformat
>             Fix For: 4.22.0
>
>         Attachments: CsvDataFormatFormatOptionIgnoredIssueTest.java
>
>
> *Severity:* High
> *Affects:* 4.15.0 through 4.22.0-SNAPSHOT (regression)
> h3. Problem
> {{CsvDataFormat}} has two stacked bugs:
> # The field is pre-initialized {{private CSVFormat csvFormat = 
> CSVFormat.DEFAULT;}} (never null), so the {{doInit()}} guard is dead code:
> {code:java}
> if (csvFormat == null && format != null) {
>     csvFormat = CSVFormat.valueOf(format);   // never reached from the DSL
> }
> {code}
> Nothing sets {{csvFormat}} from the DSL (only {{format}}), so every {{<csv 
> format="..."/>}} silently runs with {{CSVFormat.DEFAULT}} (comma-delimited).
> # Even if reached, {{CSVFormat.valueOf}} resolves against commons-csv's 
> {{CSVFormat.Predefined}}, whose names are CamelCase ({{Excel}}, {{MySQL}}, 
> {{TDF}}, ...). The model advertises uppercase {{EXCEL}}, {{INFORMIX_UNLOAD}}, 
> ... of which only {{RFC4180}} resolves; {{"EXCEL"}} would throw 
> {{IllegalArgumentException}}.
> h3. Regression
> CAMEL-22354 replaced the old {{formatName}}/{{setFormatName}} (which mapped 
> uppercase names explicitly). CAMEL-23031 fixed only the init ordering, not 
> the dead guard or the name mismatch. The Spring test XMLs were rewritten to 
> {{format="EXCEL"}} but their assertions cannot distinguish EXCEL from DEFAULT.
> h3. Failure scenario (reproduced)
> {{setFormat("MYSQL")}} (TAB delimiter) then marshal a row -> output is 
> comma-delimited {{1,2,3}} instead of TAB-delimited.
> h3. Suggested fix
> Initialize {{csvFormat = null}} (keep the {{if (csvFormat == null) csvFormat 
> = CSVFormat.DEFAULT;}} fallback), map the documented uppercase names to 
> {{Predefined}} case-insensitively, and correct the model enum list. Add a 
> test asserting a predefined format's delimiter actually takes effect.
> h3. Reproducer
> Attached {{CsvDataFormatFormatOptionIgnoredIssueTest.java}} asserts TAB 
> output for {{format=MYSQL}}; RED on current code (got comma).
> ----
> _Reported by Claude Code on behalf of Federico Mariani (Croway). A failing 
> JUnit reproducer (confirmed RED on 4.22.0-SNAPSHOT) is attached._



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to