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

Work on CAMEL-25996 started by Claus Ibsen.
-------------------------------------------
> camel-univocity-parsers - asMap fails with a NullPointerException when the 
> input has one data row and no final newline
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25996
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25996
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-univocity-parsers
>    Affects Versions: 4.18.0, 4.22.0, 4.23.0
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 4.24.0
>
>
> With {{asMap=true}}, the univocity data formats map each row by the header 
> names, which {{HeaderRowProcessor}} keeps in a thread-local value. It clears 
> that value in {{processEnded}} ({{HeaderRowProcessor}}, main 50d17f9c2614, 
> line 59), which the parser calls when it reaches the end of the input. When 
> the input does not end with a newline, the end is reached while the last row 
> is read. The header names are then gone before that row is mapped, and 
> {{MapRowIterator.convertRow}} fails with {{NullPointerException: Cannot read 
> the array length because "this.headers" is null}} ({{Unmarshaller}}, line 
> 158).
> * Since CAMEL-24170 (4.22.0), the names are read when the iterator is 
> created, after the first row ({{Unmarshaller}}, line 153). So only an input 
> with one data row and no final newline fails.
> * On 4.18.0 and 4.14.0 the names were read for each row, so any input without 
> a final newline failed.
> This is easy to hit from a YAML route, because the {{constant}} expression 
> trims the text: {{setBody: constant: "a,b\n1,2\n"}} gives {{a,b\n1,2}}.
> Checked with {{UniVocityCsvDataFormat}}, {{asMap=true}} and 
> {{headerExtractionEnabled=true}}:
> || input || 4.14.0 and 4.18.0 || 4.22.0 ||
> | {{a,b\n1,2}} | NPE | NPE |
> | {{a,b\n1,2\n3,4}} | NPE | two Maps |
> | {{a,b\n1,2\n}} | one Map | one Map |
> On 4.24.0-SNAPSHOT, with {{camel run}}: the same as 4.22.0 for univocityCsv, 
> univocityTsv and univocityFixed, and with header names given by 
> {{univocityHeader}} instead of extracted.
> *Proposed change*: take the header names from the parsing context when the 
> first row is parsed, and keep them in the iterator, instead of reading the 
> thread-local value after {{processEnded}} has cleared it.
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to