World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#8085] fix: NPE in CatalogCreateRequest constructor when type is null (#8121)
Minji Kim1c7b2de40c71
diff --git a/common/src/main/java/org/apache/gravitino/dto/requests/CatalogCreateRequest.java b/common/src/main/java/org/apache/gravitino/dto/requests/CatalogCreateRequest.javaindex dc30a7a561..3223fce6c8 100644--- a/common/src/main/java/org/apache/gravitino/dto/requests/CatalogCreateRequest.java+++ b/common/src/main/java/org/apache/gravitino/dto/requests/CatalogCreateRequest.java@@ -86,11 +86,16 @@ public class CatalogCreateRequest implements RESTRequest {+ " that doesn't support managed catalog");}- if (this.provider.equalsIgnoreCase("hadoop")) {+ if (this.provider != null && this.provider.equalsIgnoreCase("hadoop")) {// For backward compatibility, if the provider is "hadoop" (legacy case), we set the// provider to "fileset". This is because provider "hadoop" was previously used as a// "fileset" catalog. This is a special case to maintain compatibility.- this.provider = CatalogProvider.shortNameForManagedCatalog(type);+ if (type != null) {+ this.provider = CatalogProvider.shortNameForManagedCatalog(type);+ } else {+ throw new IllegalArgumentException(+ "Catalog type cannot be null when provider is \"hadoop\"");+ }}}diff --git a/common/src/test/java/org/apache/gravitino/dto/requests/TestCatalogCreateRequest.java b/common/src/test/java/org/apache/gravitino/dto/requests/TestCatalogCreateRequest.javaindex 3b5221ff1a..04544d23ee 100644--- a/common/src/test/java/org/apache/gravitino/dto/requests/TestCatalogCreateRequest.java+++ b/common/src/test/java/org/apache/gravitino/dto/requests/TestCatalogCreateRequest.java@@ -77,4 +77,18 @@ public class TestCatalogCreateRequest {JsonMappingException.class,() -> JsonUtils.objectMapper().readValue(json1, CatalogCreateRequest.class));}++ @Test+ public void testCatalogCreateRequestNullTypeHadoopProvider() {+ // Test NPE case when type is null and provider is "hadoop"+ // This should throw IllegalArgumentException instead of NPE in constructor+ IllegalArgumentException exception =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () -> new CatalogCreateRequest("catalog_test", null, "hadoop", null, null));++ // Verify the exception message+ Assertions.assertEquals(+ "Catalog type cannot be null when provider is \"hadoop\"", exception.getMessage());+ }}