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

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


The following commit(s) were added to refs/heads/main by this push:
     new 3bd04bea65 API: Null check for auto-unboxed field-id (#12165)
3bd04bea65 is described below

commit 3bd04bea65296d15b70306d99ee178e8b107627b
Author: Daniel Weeks <[email protected]>
AuthorDate: Thu Feb 6 00:53:28 2025 -0800

    API: Null check for auto-unboxed field-id (#12165)
    
    * API: Null check for auto-unboxed field id in builder
    
    * Update api/src/main/java/org/apache/iceberg/types/Types.java
    
    Co-authored-by: Eduard Tudenhoefner <[email protected]>
    
    * Update api/src/test/java/org/apache/iceberg/types/TestTypes.java
    
    Co-authored-by: Eduard Tudenhoefner <[email protected]>
    
    * Update api/src/test/java/org/apache/iceberg/types/TestTypes.java
    
    Co-authored-by: Eduard Tudenhoefner <[email protected]>
    
    ---------
    
    Co-authored-by: Eduard Tudenhoefner <[email protected]>
---
 api/src/main/java/org/apache/iceberg/types/Types.java     |  3 ++-
 api/src/test/java/org/apache/iceberg/types/TestTypes.java | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/api/src/main/java/org/apache/iceberg/types/Types.java 
b/api/src/main/java/org/apache/iceberg/types/Types.java
index 6882f71850..2c0f56b79a 100644
--- a/api/src/main/java/org/apache/iceberg/types/Types.java
+++ b/api/src/main/java/org/apache/iceberg/types/Types.java
@@ -609,7 +609,8 @@ public class Types {
       }
 
       public NestedField build() {
-        // the constructor validates the fields
+        Preconditions.checkNotNull(id, "Id cannot be null");
+        // the constructor validates the other fields
         return new NestedField(isOptional, id, name, type, doc, 
initialDefault, writeDefault);
       }
     }
diff --git a/api/src/test/java/org/apache/iceberg/types/TestTypes.java 
b/api/src/test/java/org/apache/iceberg/types/TestTypes.java
index cbc3729137..b464317c2f 100644
--- a/api/src/test/java/org/apache/iceberg/types/TestTypes.java
+++ b/api/src/test/java/org/apache/iceberg/types/TestTypes.java
@@ -18,6 +18,8 @@
  */
 package org.apache.iceberg.types;
 
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.apache.iceberg.types.Types.NestedField.required;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 
@@ -47,4 +49,15 @@ public class TestTypes {
         .isThrownBy(() -> Types.fromPrimitiveString("abcdefghij"))
         .withMessage("Cannot parse type string to primitive: abcdefghij");
   }
+
+  @Test
+  public void testNestedFieldBuilderIdCheck() {
+    assertThatExceptionOfType(NullPointerException.class)
+        .isThrownBy(() -> 
optional("field").ofType(Types.StringType.get()).build())
+        .withMessage("Id cannot be null");
+
+    assertThatExceptionOfType(NullPointerException.class)
+        .isThrownBy(() -> 
required("field").ofType(Types.StringType.get()).build())
+        .withMessage("Id cannot be null");
+  }
 }

Reply via email to