This is an automated email from the ASF dual-hosted git repository.
jshao 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 7f6635b57b [#9079] fix(catalogs): Validate Hudi catalog backend
property (#9304)
7f6635b57b is described below
commit 7f6635b57bc7e381201b3dc08c4ded8b6838a98f
Author: Hajun Yoo <[email protected]>
AuthorDate: Tue Dec 2 19:45:40 2025 +0900
[#9079] fix(catalogs): Validate Hudi catalog backend property (#9304)
### What changes were proposed in this pull request?
- Validate catalog-backend before loading the Hudi catalog backend and
throw a clear IllegalArgumentException when it is missing or blank.
- Add a unit test covering the missing-property case to ensure the error
is raised with the expected message.
### Why are the changes needed?
The previous code attempted to valueOf a null backend string, causing a
NullPointerException.
This change surfaces a clear, actionable error when the required
property is absent.
Fix: #9079
### Does this PR introduce _any_ user-facing change?
Error handling now reports a clear IllegalArgumentException if
catalog-backend is not provided. No API changes
### How was this patch tested?
-
catalogs/catalog-lakehouse-hudi/src/test/java/org/apache/gravitino/catalog/lakehouse/hudi/utils/TestCatalogUtils.java:
testLoadHudiCatalogBackendMissingProperty
- ./gradlew --no-daemon :catalogs:catalog-lakehouse-hudi:test --tests
org.apache.gravitino.catalog.lakehouse.hudi.utils.TestCatalogUtils
---
.../gravitino/catalog/lakehouse/hudi/utils/CatalogUtils.java | 9 +++++++--
.../catalog/lakehouse/hudi/utils/TestCatalogUtils.java | 12 ++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git
a/catalogs/catalog-lakehouse-hudi/src/main/java/org/apache/gravitino/catalog/lakehouse/hudi/utils/CatalogUtils.java
b/catalogs/catalog-lakehouse-hudi/src/main/java/org/apache/gravitino/catalog/lakehouse/hudi/utils/CatalogUtils.java
index 7e6a45081f..b6abf781ee 100644
---
a/catalogs/catalog-lakehouse-hudi/src/main/java/org/apache/gravitino/catalog/lakehouse/hudi/utils/CatalogUtils.java
+++
b/catalogs/catalog-lakehouse-hudi/src/main/java/org/apache/gravitino/catalog/lakehouse/hudi/utils/CatalogUtils.java
@@ -33,8 +33,13 @@ public class CatalogUtils {
private CatalogUtils() {}
public static HudiCatalogBackend loadHudiCatalogBackend(Map<String, String>
properties) {
- BackendType backendType =
-
BackendType.valueOf(properties.get(CATALOG_BACKEND).toUpperCase(Locale.ROOT));
+ String backend = properties.get(CATALOG_BACKEND);
+ if (backend == null || backend.trim().isEmpty()) {
+ throw new IllegalArgumentException(
+ "Property " + CATALOG_BACKEND + " must not be null or empty");
+ }
+
+ BackendType backendType =
BackendType.valueOf(backend.trim().toUpperCase(Locale.ROOT));
switch (backendType) {
case HMS:
HudiCatalogBackend hudiHMSBackend = new HudiHMSBackend();
diff --git
a/catalogs/catalog-lakehouse-hudi/src/test/java/org/apache/gravitino/catalog/lakehouse/hudi/utils/TestCatalogUtils.java
b/catalogs/catalog-lakehouse-hudi/src/test/java/org/apache/gravitino/catalog/lakehouse/hudi/utils/TestCatalogUtils.java
index 5f306d7bf9..86eaabde8c 100644
---
a/catalogs/catalog-lakehouse-hudi/src/test/java/org/apache/gravitino/catalog/lakehouse/hudi/utils/TestCatalogUtils.java
+++
b/catalogs/catalog-lakehouse-hudi/src/test/java/org/apache/gravitino/catalog/lakehouse/hudi/utils/TestCatalogUtils.java
@@ -35,4 +35,16 @@ public class TestCatalogUtils {
Assertions.assertInstanceOf(HudiHMSBackend.class, catalogBackend);
Assertions.assertInstanceOf(HudiHMSBackendOps.class,
catalogBackend.backendOps());
}
+
+ @Test
+ public void testLoadHudiCatalogBackendMissingProperty() {
+ IllegalArgumentException exception =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> CatalogUtils.loadHudiCatalogBackend(ImmutableMap.of()));
+ Assertions.assertTrue(
+ exception
+ .getMessage()
+ .contains("Property " + CATALOG_BACKEND + " must not be null or
empty"));
+ }
}