This is an automated email from the ASF dual-hosted git repository.

diqiu50 pushed a commit to branch branch-1.2
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/branch-1.2 by this push:
     new 6d846c06e0 [Cherry-pick to branch-1.2] Fix possible NPE in 
TagMetaService#getTagIdByTagName when tag does no… (#10298) (#10319)
6d846c06e0 is described below

commit 6d846c06e0fe2d8d293e38d1ad33217200927c47
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Mar 9 22:57:03 2026 +0800

    [Cherry-pick to branch-1.2] Fix possible NPE in 
TagMetaService#getTagIdByTagName when tag does no… (#10298) (#10319)
    
    **Cherry-pick Information:**
    - Original commit: db47023e4d429bdeefe76c45323142ba92267aa3
    - Target branch: `branch-1.2`
    - Status: ✅ Clean cherry-pick (no conflicts)
    
    ---------
    
    Co-authored-by: Aditi102005 <[email protected]>
    Co-authored-by: yuqi <[email protected]>
---
 .../hologres/HologresCatalogOperations.java        | 57 ----------------------
 .../storage/relational/service/TagMetaService.java | 14 ++++--
 .../relational/service/TestTagMetaService.java     | 12 +++++
 3 files changed, 23 insertions(+), 60 deletions(-)

diff --git 
a/catalogs-contrib/catalog-jdbc-hologres/src/main/java/org/apache/gravitino/catalog/hologres/HologresCatalogOperations.java
 
b/catalogs-contrib/catalog-jdbc-hologres/src/main/java/org/apache/gravitino/catalog/hologres/HologresCatalogOperations.java
deleted file mode 100644
index 2c2442569e..0000000000
--- 
a/catalogs-contrib/catalog-jdbc-hologres/src/main/java/org/apache/gravitino/catalog/hologres/HologresCatalogOperations.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.gravitino.catalog.hologres;
-
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import org.apache.gravitino.catalog.jdbc.JdbcCatalogOperations;
-import 
org.apache.gravitino.catalog.jdbc.converter.JdbcColumnDefaultValueConverter;
-import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
-import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter;
-import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
-import org.apache.gravitino.catalog.jdbc.operation.JdbcTableOperations;
-
-/**
- * Hologres catalog operations implementation.
- *
- * <p>Since Hologres uses the PostgreSQL JDBC driver, this class handles the 
driver deregistration
- * properly to avoid memory leaks when the catalog is closed.
- */
-public class HologresCatalogOperations extends JdbcCatalogOperations {
-
-  public HologresCatalogOperations(
-      JdbcExceptionConverter exceptionConverter,
-      JdbcTypeConverter jdbcTypeConverter,
-      JdbcDatabaseOperations databaseOperation,
-      JdbcTableOperations tableOperation,
-      JdbcColumnDefaultValueConverter columnDefaultValueConverter) {
-    super(
-        exceptionConverter,
-        jdbcTypeConverter,
-        databaseOperation,
-        tableOperation,
-        columnDefaultValueConverter);
-  }
-
-  @Override
-  protected Driver getDriver() throws SQLException {
-    return DriverManager.getDriver("jdbc:postgresql://dummy_address:12345/");
-  }
-}
diff --git 
a/core/src/main/java/org/apache/gravitino/storage/relational/service/TagMetaService.java
 
b/core/src/main/java/org/apache/gravitino/storage/relational/service/TagMetaService.java
index 99e575a24d..b56f703d2c 100644
--- 
a/core/src/main/java/org/apache/gravitino/storage/relational/service/TagMetaService.java
+++ 
b/core/src/main/java/org/apache/gravitino/storage/relational/service/TagMetaService.java
@@ -410,10 +410,18 @@ public class TagMetaService {
   }
 
   public Long getTagIdByTagName(Long metalakeId, String tagName) {
-    return SessionUtils.getWithoutCommit(
+    TagPO tagPO =
+        SessionUtils.getWithoutCommit(
             TagMetaMapper.class,
-            mapper -> mapper.selectTagMetaByMetalakeIdAndName(metalakeId, 
tagName))
-        .getTagId();
+            mapper -> mapper.selectTagMetaByMetalakeIdAndName(metalakeId, 
tagName));
+
+    if (tagPO == null) {
+      throw new NoSuchEntityException(
+          NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+          Entity.EntityType.TAG.name().toLowerCase(),
+          tagName);
+    }
+    return tagPO.getTagId();
   }
 
   private List<TagPO> getTagPOsByMetalakeAndNames(String metalakeName, 
List<String> tagNames) {
diff --git 
a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTagMetaService.java
 
b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTagMetaService.java
index 365d7081bf..0add50e617 100644
--- 
a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTagMetaService.java
+++ 
b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTagMetaService.java
@@ -1112,6 +1112,18 @@ public class TestTagMetaService extends TestJDBCBackend {
     Assertions.assertEquals(21, countAllTagRel(tagEntity1.id()));
   }
 
+  @TestTemplate
+  public void testGetTagIdByTagNameWhenTagNotFound() throws IOException {
+    createAndInsertMakeLake(METALAKE_NAME);
+
+    TagMetaService tagMetaService = TagMetaService.getInstance();
+    long metalakeId = 
MetalakeMetaService.getInstance().getMetalakeIdByName(METALAKE_NAME);
+
+    Assertions.assertThrows(
+        NoSuchEntityException.class,
+        () -> tagMetaService.getTagIdByTagName(metalakeId, "missing_tag"));
+  }
+
   private boolean containsGenericEntity(
       List<GenericEntity> genericEntities, String name, Entity.EntityType 
entityType) {
     return genericEntities.stream().anyMatch(e -> e.name().equals(name) && 
e.type() == entityType);

Reply via email to