rootvector2 opened a new pull request, #629:
URL: https://github.com/apache/commons-csv/pull/629

   `print(Object, CharSequence, Appendable, boolean)` sends a null value 
straight to `out.append(value)` and never reaches `printWithQuotes`, so the 
encapsulation `MINIMAL` does for an empty value at the start of a record is 
skipped. That rule exists precisely for this case, as its own comment says an 
empty line has no tokens. The result is that a record whose first value is 
null, and whose null string renders empty, prints as a blank line. 
`CSVFormat.DEFAULT` enables `ignoreEmptyLines`, so the record is silently 
dropped when the output is read back: printing `[a]`, `[null]`, `[b]` gives 
`a\r\n\r\nb\r\n`, which parses as 2 records. The same loss hits any 
`DEFAULT`-derived format, including `MONGODB_CSV` and `INFORMIX_UNLOAD`, and 
any format using `setNullString("")`. Found round-tripping printer output with 
null values back through the parser.
   
   The fix encapsulates the empty null value when it starts a record, a quote 
character is set, and the quote mode is `MINIMAL` or unset, which is the same 
condition `printWithQuotes` already applies to an empty `CharSequence`. 
`ALL_NON_NULL` and `NON_NUMERIC` are left alone since they use the bare empty 
field to encode null, and formats without a quote character have nothing to 
encapsulate with. Two existing assertions move because a leading null now 
prints like a leading `""`; `testPrintRecordsWithObjectArray` was pinning six 
blank lines for six records, which is the bug itself.
   
   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [ ] Read the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use 
Artificial Intelligence (AI).
   - [ ] I used AI to create any part of, or all of, this pull request. Which 
AI tool was used to create this pull request, and to what extent did it 
contribute?
   - [x] Run a successful build using the default 
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command 
line by itself.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied. This may not always be possible, 
but it is a best practice.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body. Note that a maintainer may squash commits during the merge process.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to