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

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


The following commit(s) were added to refs/heads/main by this push:
     new f2528b1519 [#8009] fix: prevent NPE in validate() when 
ModelVersionUpdatesRequest updates is null (#8021)
f2528b1519 is described below

commit f2528b1519a7821a493a75051eb4a113d82dcd5c
Author: Joonseo Lee <[email protected]>
AuthorDate: Tue Aug 12 20:48:55 2025 +0900

    [#8009] fix: prevent NPE in validate() when ModelVersionUpdatesRequest 
updates is null (#8021)
    
    ### What changes were proposed in this pull request?
    
    This PR adds a null check for the updates field in
    ModelVersionUpdateRequest.validate().
    If updates is null, the method now throws an IllegalArgumentException
    with a clear message instead of triggering a NullPointerException.
    This ensures that validation fails gracefully when no updates are
    provided.
    
    ### Why are the changes needed?
    
    Previously, when updates was null, calling updates.forEach(...) would
    result in a NullPointerException, which is less informative and harder
    to debug.
    By explicitly checking for null and throwing IllegalArgumentException,
    the code provides a clear error message and prevents unexpected runtime
    failures.
    
    Fix: #8009
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    Added a test to verify that validate() throws IllegalArgumentException
    when updates is null.
---
 .../dto/requests/ModelVersionUpdatesRequest.java   |  4 +++
 .../requests/TestModelVersionUpdatesRequest.java}  | 33 ++++++++--------------
 2 files changed, 15 insertions(+), 22 deletions(-)

diff --git 
a/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdatesRequest.java
 
b/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdatesRequest.java
index 14e2675041..13ec1d07e3 100644
--- 
a/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdatesRequest.java
+++ 
b/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdatesRequest.java
@@ -41,6 +41,10 @@ public class ModelVersionUpdatesRequest implements 
RESTRequest {
   /** {@inheritDoc} */
   @Override
   public void validate() throws IllegalArgumentException {
+    if (updates == null) {
+      throw new IllegalArgumentException("updates cannot be null");
+    }
+
     updates.forEach(ModelVersionUpdateRequest::validate);
   }
 }
diff --git 
a/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdatesRequest.java
 
b/common/src/test/java/org/apache/gravitino/dto/requests/TestModelVersionUpdatesRequest.java
similarity index 54%
copy from 
common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdatesRequest.java
copy to 
common/src/test/java/org/apache/gravitino/dto/requests/TestModelVersionUpdatesRequest.java
index 14e2675041..7fcf1c980f 100644
--- 
a/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdatesRequest.java
+++ 
b/common/src/test/java/org/apache/gravitino/dto/requests/TestModelVersionUpdatesRequest.java
@@ -16,31 +16,20 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.gravitino.dto.requests;
 
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.List;
-import lombok.AllArgsConstructor;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.ToString;
-import org.apache.gravitino.rest.RESTRequest;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestModelVersionUpdatesRequest {
 
-/** Represents a several request to update a model version. */
-@Getter
-@EqualsAndHashCode
-@AllArgsConstructor
-@NoArgsConstructor(force = true)
-@ToString
-public class ModelVersionUpdatesRequest implements RESTRequest {
-  @JsonProperty("updates")
-  private final List<ModelVersionUpdateRequest> updates;
+  @Test
+  public void testModelVersionUpdatesRequestWithUpdatesNull() {
+    ModelVersionUpdatesRequest modelVersionUpdatesRequest = new 
ModelVersionUpdatesRequest(null);
 
-  /** {@inheritDoc} */
-  @Override
-  public void validate() throws IllegalArgumentException {
-    updates.forEach(ModelVersionUpdateRequest::validate);
+    Assertions.assertThrows(
+        IllegalArgumentException.class,
+        modelVersionUpdatesRequest::validate,
+        "updates cannot be null");
   }
 }

Reply via email to