[
https://issues.apache.org/jira/browse/CAMEL-24546?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
mayur mohan updated CAMEL-24546:
--------------------------------
Description:
When camel-csv unmarshal encounters malformed CSV input (e.g. a quoted field
with extra characters after the closing quote), Apache Commons CSV throws a raw
IOException with a technical message that is hard to diagnose for operators.
*Observed error:*
{noformat}
java.io.IOException: (line 1) invalid char between encapsulated token and
delimiter
at org.apache.commons.csv.Lexer.parseEncapsulatedToken(Lexer.java:281)
at org.apache.commons.csv.Lexer.nextToken(Lexer.java:158)
at org.apache.commons.csv.CSVParser.nextRecord(CSVParser.java:674)
at org.apache.commons.csv.CSVParser.createHeaders(CSVParser.java:483)
at org.apache.commons.csv.CSVParser.<init>(CSVParser.java:412)
at org.apache.commons.csv.CSVParser.<init>(CSVParser.java:378)
at
org.apache.camel.dataformat.csv.CsvUnmarshaller$BulkCsvUnmarshaller.unmarshal(CsvUnmarshaller.java:105)
at
org.apache.camel.dataformat.csv.CsvDataFormat.unmarshal(CsvDataFormat.java:95)
at
com.sap.it.rt.csvtoxml.converter.internal.CsvToJavaListConverter.unmarshalCsv(CsvToJavaListConverter.java:57)
at
com.sap.it.rt.csvtoxml.converter.CsvToXmlProcessor.process(CsvToXmlProcessor.java:79)
at
org.apache.camel.support.ObjectHelper.invokeMethodSafe(ObjectHelper.java:403)
at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:494)
at
org.apache.camel.component.bean.MethodInfo$1.doProceed(MethodInfo.java:316)
at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:286)
at
org.apache.camel.component.bean.AbstractBeanProcessor.process(AbstractBeanProcessor.java:146)
at
org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:81)
at
org.apache.camel.support.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:104)
at
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.doRun(RedeliveryErrorHandler.java:818)
at
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.run(RedeliveryErrorHandler.java:726)
at
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:193)
at
org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:64)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:185)
at
org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:398)
{noformat}
Line 1 is usually the header. A quoted field was closed, then extra characters
appeared before the delimiter (example: {{"OrderId"x,"Name"}}).
*File:*
{{components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvUnmarshaller.java}}
Classes: {{BulkCsvUnmarshaller}}, {{StreamCsvUnmarshaller}}
*Proposed fix:*
Add a {{wrapCsvParseError(IOException)}} helper in {{CsvUnmarshaller}} that
detects the encapsulated-token message and wraps it with a human-readable
explanation. Both {{BulkCsvUnmarshaller.unmarshal}} and
{{StreamCsvUnmarshaller.unmarshal}} call this helper on caught {{IOException}}.
*Error message after fix:*
{noformat}
CSV parse failed: (line 1) invalid char between encapsulated token and
delimiter. A quoted field has extra characters after the closing quote and
before the delimiter (example: "abc"x,def). Check delimiter, quote character,
and escaped quotes ("").
{noformat}
This is a cosmetic/diagnostic-only change. No behavior, API, or data format
change. Bad CSV still fails — it just fails with a clearer message.
was:
When camel-csv unmarshal encounters malformed CSV (e.g. a quoted field with
extra characters after the closing quote), Apache Commons CSV throws a raw
IOException with a technical message that is hard to diagnose:
java.io.IOException: (line 1) invalid char between encapsulated token and
delimiter
at org.apache.commons.csv.Lexer.parseEncapsulatedToken(Lexer.java:281)
at org.apache.commons.csv.CSVParser.createHeaders(CSVParser.java:483)
at
org.apache.camel.dataformat.csv.CsvUnmarshaller$BulkCsvUnmarshaller.unmarshal(CsvUnmarshaller.java:105)
at
org.apache.camel.dataformat.csv.CsvDataFormat.unmarshal(CsvDataFormat.java:95)
The fix wraps the IOException in CsvUnmarshaller (both BulkCsvUnmarshaller and
StreamCsvUnmarshaller) with a diagnostic message identifying the root cause and
guiding operators to check their delimiter and quote character configuration.
Error message after fix:
CSV parse failed: (line 1) invalid char between encapsulated token and
delimiter. A quoted field has extra characters after the closing quote and
before the delimiter (example: "abc"x,def). Check delimiter, quote character,
and escaped quotes ("").
This is a cosmetic/diagnostic-only change. No behavior, API, or data format
change.
> camel-csv: wrap CSV parse IOException with diagnostic message in
> CsvUnmarshaller
> --------------------------------------------------------------------------------
>
> Key: CAMEL-24546
> URL: https://issues.apache.org/jira/browse/CAMEL-24546
> Project: Camel
> Issue Type: Improvement
> Reporter: mayur mohan
> Priority: Minor
>
> When camel-csv unmarshal encounters malformed CSV input (e.g. a quoted field
> with extra characters after the closing quote), Apache Commons CSV throws a
> raw IOException with a technical message that is hard to diagnose for
> operators.
> *Observed error:*
> {noformat}
> java.io.IOException: (line 1) invalid char between encapsulated token and
> delimiter
> at org.apache.commons.csv.Lexer.parseEncapsulatedToken(Lexer.java:281)
> at org.apache.commons.csv.Lexer.nextToken(Lexer.java:158)
> at org.apache.commons.csv.CSVParser.nextRecord(CSVParser.java:674)
> at org.apache.commons.csv.CSVParser.createHeaders(CSVParser.java:483)
> at org.apache.commons.csv.CSVParser.<init>(CSVParser.java:412)
> at org.apache.commons.csv.CSVParser.<init>(CSVParser.java:378)
> at
> org.apache.camel.dataformat.csv.CsvUnmarshaller$BulkCsvUnmarshaller.unmarshal(CsvUnmarshaller.java:105)
> at
> org.apache.camel.dataformat.csv.CsvDataFormat.unmarshal(CsvDataFormat.java:95)
> at
> com.sap.it.rt.csvtoxml.converter.internal.CsvToJavaListConverter.unmarshalCsv(CsvToJavaListConverter.java:57)
> at
> com.sap.it.rt.csvtoxml.converter.CsvToXmlProcessor.process(CsvToXmlProcessor.java:79)
> at
> org.apache.camel.support.ObjectHelper.invokeMethodSafe(ObjectHelper.java:403)
> at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:494)
> at
> org.apache.camel.component.bean.MethodInfo$1.doProceed(MethodInfo.java:316)
> at
> org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:286)
> at
> org.apache.camel.component.bean.AbstractBeanProcessor.process(AbstractBeanProcessor.java:146)
> at
> org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:81)
> at
> org.apache.camel.support.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:104)
> at
> org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.doRun(RedeliveryErrorHandler.java:818)
> at
> org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.run(RedeliveryErrorHandler.java:726)
> at
> org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:193)
> at
> org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:64)
> at org.apache.camel.processor.Pipeline.process(Pipeline.java:185)
> at
> org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:398)
> {noformat}
> Line 1 is usually the header. A quoted field was closed, then extra
> characters appeared before the delimiter (example: {{"OrderId"x,"Name"}}).
> *File:*
> {{components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvUnmarshaller.java}}
> Classes: {{BulkCsvUnmarshaller}}, {{StreamCsvUnmarshaller}}
> *Proposed fix:*
> Add a {{wrapCsvParseError(IOException)}} helper in {{CsvUnmarshaller}} that
> detects the encapsulated-token message and wraps it with a human-readable
> explanation. Both {{BulkCsvUnmarshaller.unmarshal}} and
> {{StreamCsvUnmarshaller.unmarshal}} call this helper on caught
> {{IOException}}.
> *Error message after fix:*
> {noformat}
> CSV parse failed: (line 1) invalid char between encapsulated token and
> delimiter. A quoted field has extra characters after the closing quote and
> before the delimiter (example: "abc"x,def). Check delimiter, quote character,
> and escaped quotes ("").
> {noformat}
> This is a cosmetic/diagnostic-only change. No behavior, API, or data format
> change. Bad CSV still fails — it just fails with a clearer message.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)