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 d23c046a5c [#8656] Improvement: Validate empty table updates in
TableUpdatesRequest (#10201)
d23c046a5c is described below
commit d23c046a5cbb459006197286e99dc94a463085e2
Author: Arpit Saha <[email protected]>
AuthorDate: Thu Mar 5 04:40:46 2026 +0530
[#8656] Improvement: Validate empty table updates in TableUpdatesRequest
(#10201)
### What changes were proposed in this pull request?
Adds validation in `TableUpdatesRequest.validate()` to ensure that the
updates list is not empty before applying table updates.
If the list is empty, an IllegalArgumentException is thrown.\
Additionally, a unit test (`testValidateEmptyUpdates`) is added to
verify that the validation correctly throws an exception when an empty
updates list is provided.
### Why are the changes needed?
Currently,
`TableUpdatesRequest.validate()` only checks that updates is not null.
However, an empty list of updates is also invalid because a table update
request without any updates should not be allowed.
This change ensures stronger validation and prevents invalid request
from being processed.
Fix: #8656
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
(Please test your changes, and provide instructions on how to test it:
Added a new unit test
1. `testValidateEmptyUpdates` in `TestTableUpdatesRequest`.
2. The test verifies that IllegalArgumentException is thrown when
updates is empty.
3. Existing tests were run to ensure no regressions.
---------
Co-authored-by: Copilot <[email protected]>
---
.../org/apache/gravitino/dto/requests/TableUpdatesRequest.java | 1 +
.../apache/gravitino/dto/requests/TestTableUpdatesRequest.java | 8 ++++++++
2 files changed, 9 insertions(+)
diff --git
a/common/src/main/java/org/apache/gravitino/dto/requests/TableUpdatesRequest.java
b/common/src/main/java/org/apache/gravitino/dto/requests/TableUpdatesRequest.java
index 02db343bed..e347f9b681 100644
---
a/common/src/main/java/org/apache/gravitino/dto/requests/TableUpdatesRequest.java
+++
b/common/src/main/java/org/apache/gravitino/dto/requests/TableUpdatesRequest.java
@@ -57,6 +57,7 @@ public class TableUpdatesRequest implements RESTRequest {
@Override
public void validate() throws IllegalArgumentException {
Preconditions.checkArgument(updates != null, "updates must not be null");
+ Preconditions.checkArgument(!updates.isEmpty(), "updates must not be
empty");
updates.forEach(RESTRequest::validate);
}
}
diff --git
a/common/src/test/java/org/apache/gravitino/dto/requests/TestTableUpdatesRequest.java
b/common/src/test/java/org/apache/gravitino/dto/requests/TestTableUpdatesRequest.java
index b8e49a3a82..f4d5ad0fcb 100644
---
a/common/src/test/java/org/apache/gravitino/dto/requests/TestTableUpdatesRequest.java
+++
b/common/src/test/java/org/apache/gravitino/dto/requests/TestTableUpdatesRequest.java
@@ -310,6 +310,14 @@ public class TestTableUpdatesRequest {
JsonUtils.objectMapper().readTree(expected),
JsonUtils.objectMapper().readTree(jsonString));
}
+ @Test
+ public void testValidateEmptyUpdates() {
+ TableUpdatesRequest request = new TableUpdatesRequest(ImmutableList.of());
+ Throwable exception =
+ Assertions.assertThrows(IllegalArgumentException.class,
request::validate);
+ Assertions.assertEquals("updates must not be empty",
exception.getMessage());
+ }
+
@Test
public void testUpdateColumnCommentWithEmptyString() {
TableUpdateRequest.UpdateTableColumnCommentRequest request =