Open
Conversation
Add null check before iterating map values to prevent crashes when handling null map columns. This matches the pattern used for array null handling in the previous fix.
yifan-c
reviewed
Feb 3, 2026
| let row = result.first! | ||
|
|
||
| XCTAssertNil(row.column("nullable_map")?.int32StringMap) | ||
| XCTAssertNil(row.column("empty_map")?.int32StringMap) |
Collaborator
There was a problem hiding this comment.
Should it assert on returning an empty map, instead of nil? The semantics seems wrong.
It is not a behavior changed in the patch, although.
|
|
||
| var map: [K: V] = [:] | ||
|
|
||
| let iterator = cass_iterator_from_map(self.rawPointer) |
Collaborator
There was a problem hiding this comment.
Should null case be handled in this method to create iterator? I am referring to #77
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.
Add null check before iterating map values to prevent crashes when handling null map columns.
Motivation:
When handling Cassandra query results containing null map columns, the
toMapmethod would crash because it attempted to create an iterator from a null pointer without first checking if the value was null. This is the same issue that was addressed for arrays in PR #77, but the map handling code path was missed in that fix.Modifications:
cass_value_is_nullbefore creating the map iterator inData+Maps.swift:272testMapWithNullIteratorHandlingthat verifies null maps, empty maps, and valid maps are all handled correctlyResult:
Map columns containing null values now return
nilinstead of crashing when accessed. This provides consistent null-handling behavior across all collection types (arrays, sets, and maps) and prevents runtime crashes when querying tables with nullable map columns.