World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#10125] fix(server): prevent NPE when statistics update request body is null (#10190)
ChangJun Rho0372c01df95b
diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/StatisticOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/StatisticOperations.javaindex 1f4999dfcf..420869c020 100644--- a/server/src/main/java/org/apache/gravitino/server/web/rest/StatisticOperations.java+++ b/server/src/main/java/org/apache/gravitino/server/web/rest/StatisticOperations.java@@ -81,6 +81,9 @@ public class StatisticOperations {private static final Logger LOG = LoggerFactory.getLogger(StatisticOperations.class);+ private static final String NULL_STATS_UPDATE_REQUEST_BODY_ERROR =+ "Statistics update request body cannot be null";+@Context private HttpServletRequest httpRequest;private final StatisticDispatcher statisticDispatcher;@@ -160,6 +163,9 @@ public class StatisticOperations {return Utils.doAs(httpRequest,() -> {+ if (request == null) {+ throw new IllegalArgumentException(NULL_STATS_UPDATE_REQUEST_BODY_ERROR);+ }request.validate();MetadataObject object =MetadataObjects.parse(diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestStatisticOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestStatisticOperations.javaindex dc3055a550..992dd73ebe 100644--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestStatisticOperations.java+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestStatisticOperations.java@@ -371,6 +371,35 @@ public class TestStatisticOperations extends JerseyTest {UnmodifiableStatisticException.class.getSimpleName(), errorResp4.getType());}+ @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());+ Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType());++ ErrorResponse errorResp = resp.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.ILLEGAL_ARGUMENTS_CODE, errorResp.getCode());+ Assertions.assertEquals(IllegalArgumentException.class.getSimpleName(), errorResp.getType());+ }+@Testpublic void testDropTableStatistics() {StatisticsDropRequest req = new StatisticsDropRequest(new String[] {"test1", "test2"});