Pass normalized separator in CsvSchema.withArrayElementSeparator (avoid null state / NPE) - #710
uttam12331 wants to merge 2 commits into
Conversation
|
Sounds good! CLA needed if not sent before -- adding release notes would be great too. But one question/suggestion: might make sense to target 2.21 as backport (2.21 latest LTS version)? |
…state `CsvSchema.withArrayElementSeparator(String)` normalizes a null argument to "" in the local `sep` and uses it for the equality check, but then passes the raw `separator` to the copy constructor, so `withArrayElementSeparator(null)` leaves `_arrayElementSeparator` null. `hasArrayElementSeparator()` then NPEs on `!_arrayElementSeparator.isEmpty()`, as does a later `withArrayElementSeparator` on `_arrayElementSeparator.equals(sep)`. Pass the already-normalized `sep`, add a regression test, and add release notes.
e31a3b8 to
3a43684
Compare
|
Thanks @cowtowncoder! Retargeted this to |
|
I've filled and signed the 2026 ICLA ( |
|
@uttam12331 email to "cla" at fasterxml dot com. |
|
@uttam12331 any news on CLA? |
Summary
CsvSchema.withArrayElementSeparator(String separator)normalizes anullargument to""in the localsepand usessepfor the equality check, but then passes the rawseparatorto the copy constructor:The copy constructor stores the value directly, so
withArrayElementSeparator(null)leaves_arrayElementSeparator == null.Impact
This breaks the field's non-null invariant:
hasArrayElementSeparator()doesreturn !_arrayElementSeparator.isEmpty();→NullPointerException.withArrayElementSeparator(...)call NPEs on_arrayElementSeparator.equals(sep).Every sibling builder stores exactly the value it compared against (e.g.
withColumnSeparatorcompares_columnSeparator == sepand constructs withsep);withArrayElementSeparatoris the only one that comparessepbut constructs withseparator.Fix
Pass the already-normalized
sep:Tests
Added
CsvSchemaTest.testWithArrayElementSeparatorNull, which sets a separator, clears it withwithArrayElementSeparator(null), and assertshasArrayElementSeparator()returnsfalse(and does not throw) — this fails with an NPE on the current code and passes with the fix.Happy to add a
release-notes/CREDITSentry or sign the CLA if needed.