Skip to content

fix(json): return a parse error for a list type missing 'element' - #997

Merged
wgtmac merged 1 commit into
apache:mainfrom
LuciferYang:fix/sweep-10-listtype-missing-element
Oct 11, 2026
Merged

wgtmac merged 1 commit into
apache:mainfrom
LuciferYang:fix/sweep-10-listtype-missing-element

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

What

ListTypeFromJson in src/iceberg/json_serde.cc read the element type with the const json[kElement] accessor. For a list type object without an "element" key this is undefined behavior in nlohmann: with assertions enabled it aborts on JSON_ASSERT, and under NDEBUG it dereferences the end iterator. Table metadata with a list-typed field that lacks "element" reaches it through SchemaFromJson.

Follow-up to #982 (#982 (review)). Closes #996.

How

Read the key with GetJsonValue<nlohmann::json>(json, kElement) and pass the result to TypeFromJson, the same way MapTypeFromJson reads key and value. A missing key now returns JsonParseError. This was the only const json[key] read in src/iceberg that did not check the key exists first.

Testing

JsonInternalTest.ListTypeFromJsonMissingElement passes a list type without "element" to TypeFromJson and expects kJsonParseError with "Missing 'element'". Without the fix the test aborts with Assertion failed: (it != m_data.m_value.object->end()) in json.hpp.

ListTypeFromJson read the nested element type with the raw const
json[kElement] accessor, which is undefined behavior (an assertion in
debug nlohmann builds) when a list type object is missing the required
'element' key. Use GetJsonValue<nlohmann::json>(json, kElement) like
the sibling MapTypeFromJson does, so malformed schema or table-metadata
JSON yields JsonParseError instead of asserting.
Copilot AI balanced review requested due to automatic review settings October 10, 2026 13:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wgtmac
wgtmac merged commit ed6608d into apache:main Oct 11, 2026
15 checks passed
@LuciferYang

Copy link
Copy Markdown
Contributor Author

Thank you @wgtmac

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.

bug: ListTypeFromJson hits undefined behavior when a list type has no "element"

3 participants