This is an automated email from the ASF dual-hosted git repository.

wgtmac pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new ed6608de fix(json): return a parse error for a list type missing 
'element' (#997)
ed6608de is described below

commit ed6608de5d3095550dd1631d9d0a4073b3034e1e
Author: YangJie <[email protected]>
AuthorDate: Sun Oct 11 09:21:45 2026 -0400

    fix(json): return a parse error for a list type missing 'element' (#997)
    
    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.
---
 src/iceberg/json_serde.cc           |  4 +++-
 src/iceberg/test/json_serde_test.cc | 10 ++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/iceberg/json_serde.cc b/src/iceberg/json_serde.cc
index 1f5caf8f..6b7800ae 100644
--- a/src/iceberg/json_serde.cc
+++ b/src/iceberg/json_serde.cc
@@ -630,7 +630,9 @@ Result<std::unique_ptr<Type>> StructTypeFromJson(const 
nlohmann::json& json) {
 }
 
 Result<std::unique_ptr<Type>> ListTypeFromJson(const nlohmann::json& json) {
-  ICEBERG_ASSIGN_OR_RAISE(auto element_type, TypeFromJson(json[kElement]));
+  ICEBERG_ASSIGN_OR_RAISE(
+      auto element_type,
+      GetJsonValue<nlohmann::json>(json, kElement).and_then(TypeFromJson));
   ICEBERG_ASSIGN_OR_RAISE(auto element_id, GetJsonValue<int32_t>(json, 
kElementId));
   ICEBERG_ASSIGN_OR_RAISE(auto element_required,
                           GetJsonValue<bool>(json, kElementRequired));
diff --git a/src/iceberg/test/json_serde_test.cc 
b/src/iceberg/test/json_serde_test.cc
index cde82293..f375164f 100644
--- a/src/iceberg/test/json_serde_test.cc
+++ b/src/iceberg/test/json_serde_test.cc
@@ -193,6 +193,16 @@ TEST(JsonInternalTest, 
SchemaFieldRejectsNonUtcTimestamptzDefault) {
   EXPECT_TRUE(FieldFromJson(utc).has_value());
 }
 
+TEST(JsonInternalTest, ListTypeFromJsonMissingElement) {
+  nlohmann::json invalid_json =
+      R"({"type":"list","element-id":1,"element-required":true})"_json;
+  // missing "element"
+
+  auto result = TypeFromJson(invalid_json);
+  EXPECT_THAT(result, IsError(ErrorKind::kJsonParseError));
+  EXPECT_THAT(result, HasErrorMessage("Missing 'element'"));
+}
+
 TEST(JsonInternalTest, SortField) {
   auto identity_transform = Transform::Identity();
 

Reply via email to