Skip to content

Handle null name in CSVRecord accessors under ignoreHeaderCase#628

Merged
garydgregory merged 1 commit into
apache:masterfrom
rootvector2:null-name-ignore-header-case
Jul 23, 2026
Merged

Handle null name in CSVRecord accessors under ignoreHeaderCase#628
garydgregory merged 1 commit into
apache:masterfrom
rootvector2:null-name-ignore-header-case

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

ignoreHeaderCase backs the header map with a TreeMap on String.CASE_INSENSITIVE_ORDER whose comparator rejects null keys, so a null name throws NullPointerException from CSVRecord.isMapped/isSet/get (and get(Enum) with a null enum) where the default LinkedHashMap path returns false or throws the documented IllegalArgumentException. guard the null name in isMapped (a null name is never a mapped header) and get (report the missing mapping) so the contract is the same regardless of ignoreHeaderCase; isSet is fixed transitively. found by passing a null name to the accessors under ignoreHeaderCase.

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance 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?
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • 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.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • 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.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 null column names in CSVRecord.get(String) to avoid TreeMap/case-insensitive header map NullPointerException and throw IllegalArgumentException instead.
  • Guard null column names in CSVRecord.isMapped(String) so it returns false consistently (and fixes isSet(String) via short-circuiting).
  • Add a parameterized regression test covering both ignoreHeaderCase=false and true.

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 garydgregory changed the title handle null name in CSVRecord accessors under ignoreHeaderCase Handle null name in CSVRecord accessors under ignoreHeaderCase Jul 23, 2026
@garydgregory
garydgregory merged commit 6f3b97a into apache:master Jul 23, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants