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

   ### What would you like to be improved?
   
   The problem is that the statistics update endpoint (PUT 
/metalakes/{metalake}/objects/{type}/{fullName}/statistics) can return a 500 
Internal Server Error when the request body is null, even though this is a 
client-side issue. In StatisticOperations.updateStatistics(...), the method 
catches exceptions but then dereferences the request again inside the catch 
block (request.getUpdates().keySet()). If the request is null, this triggers a 
second NullPointerException during error handling, and results in a server 
error.
   
   See 
/server/src/main/java/org/apache/gravitino/server/web/rest/StatisticOperations.java
   
   
   ### How should we improve?
   
   A possible solution is to change StatisticOperations.updateStatistics. Add 
an explicit null check before request.validate() and throw an 
IllegalArgumentException when the request is null, then make the catch block 
null-safe.
   
   Here a unit test to help:
   ```
   @Test
   public void testUpdateTableStatisticsWithNullRequestBody() {
     when(tableDispatcher.tableExists(any())).thenReturn(true);
   
     MetadataObject tableObject =
         MetadataObjects.parse(
             String.format("%s.%s.%s", catalog, schema, table), 
MetadataObject.Type.TABLE);
   
     Response resp =
         target(
                 "/metalakes/"
                     + metalake
                     + "/objects/"
                     + tableObject.type()
                     + "/"
                     + tableObject.fullName()
                     + "/statistics")
             .request(MediaType.APPLICATION_JSON_TYPE)
             .accept("application/vnd.gravitino.v1+json")
             .put(entity("null", MediaType.APPLICATION_JSON_TYPE));
   
     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