Handle null name in CSVRecord accessors under ignoreHeaderCase#628
Merged
garydgregory merged 1 commit intoJul 23, 2026
Merged
Conversation
the case-insensitive header map used by ignoreHeaderCase rejects null keys, so guard the name in isMapped and get to return false / throw IllegalArgumentException like the default case-sensitive path.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes CSVRecord name-based accessors behave consistently when CSVFormat.Builder#setIgnoreHeaderCase(true) is enabled, preventing NullPointerException for null column names by treating null as “not mapped” and reporting a missing mapping via the documented IllegalArgumentException.
Changes:
- Guard
nullcolumn names inCSVRecord.get(String)to avoidTreeMap/case-insensitive header mapNullPointerExceptionand throwIllegalArgumentExceptioninstead. - Guard
nullcolumn names inCSVRecord.isMapped(String)so it returnsfalseconsistently (and fixesisSet(String)via short-circuiting). - Add a parameterized regression test covering both
ignoreHeaderCase=falseandtrue.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/main/java/org/apache/commons/csv/CSVRecord.java | Adds null guards in get(String) and isMapped(String) to align behavior across header-map implementations. |
| src/test/java/org/apache/commons/csv/CSVRecordTest.java | Adds a parameterized test ensuring null name accessors behave consistently regardless of ignoreHeaderCase. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
garydgregory
added a commit
that referenced
this pull request
Jul 23, 2026
garydgregory
added a commit
that referenced
this pull request
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ignoreHeaderCasebacks the header map with aTreeMaponString.CASE_INSENSITIVE_ORDERwhose comparator rejects null keys, so a null name throwsNullPointerExceptionfromCSVRecord.isMapped/isSet/get(andget(Enum)with a null enum) where the defaultLinkedHashMappath returnsfalseor throws the documentedIllegalArgumentException. guard the null name inisMapped(a null name is never a mapped header) andget(report the missing mapping) so the contract is the same regardless ofignoreHeaderCase;isSetis fixed transitively. found by passing a null name to the accessors underignoreHeaderCase.mvn; that'smvnon the command line by itself.