justinmclean opened a new issue, #10124:
URL: https://github.com/apache/gravitino/issues/10124

   ### What would you like to be improved?
   
   The current error-handling flow in StatisticOperations is fragile when 
request payloads are null or invalid. In both partition and table statistics 
update paths, the catch block dereferences request.getUpdates() to build error 
context, which can throw a new NullPointerException and mask the original 
validation failure. This leads to incorrect 500 responses instead of consistent 
client-facing validation errors (400), and makes debugging harder because the 
original cause is lost.
   
   ### How should we improve?
   
   The fix is to make catch-path error formatting null-safe and preserve the 
original exception. Build the partitions/stat names string defensively (for 
example, using an empty fallback when request or request.getUpdates() is null), 
then pass the original exception to ExceptionHandlers. 
   
   Here's a unit test to help:
   ```
   @Test
   public void 
testUpdatePartitionStatisticsShouldNotThrowWhenRequestUpdatesIsNull() {
     StatisticOperations operations = new StatisticOperations(manager);
     HttpServletRequest mockRequest = mock(HttpServletRequest.class);
     try {
       FieldUtils.writeField(operations, "httpRequest", mockRequest, true);
     } catch (IllegalAccessException e) {
       throw new RuntimeException(e);
     }
   
     PartitionStatisticsUpdateRequest req = new 
PartitionStatisticsUpdateRequest();
     Response resp =
         Assertions.assertDoesNotThrow(
             () ->
                 operations.updatePartitionStatistics(
                     metalake, "table", String.format("%s.%s.%s", catalog, 
schema, table), req));
     Assertions.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), 
resp.getStatus());
   }
   
   ```
   
   Place in 
server/src/test/java/org/apache/gravitino/server/web/rest/TestStatisticOperations.java


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to