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 d6ff0e3268 [#7515] feat(core): Improve fromComment in StringIdentifier 
(#7544)
d6ff0e3268 is described below

commit d6ff0e3268e15eb73092d33e573f9a9548749694
Author: BIN <weixubin...@gmail.com>
AuthorDate: Fri Jul 4 11:24:32 2025 +0800

    [#7515] feat(core): Improve fromComment in StringIdentifier (#7544)
    
    ### What changes were proposed in this pull request?
    
    Improve fromComment in StringIdentifier
    
    ### Why are the changes needed?
    
    Fix: #7515
    
    ### Does this PR introduce _any_ user-facing change?
    
    no
    
    ### How was this patch tested?
    
    Unit tests
    
    ---------
    
    Co-authored-by: senlizishi <weixu...@gmail.com>
---
 .../main/java/org/apache/gravitino/StringIdentifier.java  | 15 ++++++++++++---
 .../java/org/apache/gravitino/TestStringIdentifier.java   | 12 ++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/apache/gravitino/StringIdentifier.java 
b/core/src/main/java/org/apache/gravitino/StringIdentifier.java
index c60846f6de..d2ef219253 100644
--- a/core/src/main/java/org/apache/gravitino/StringIdentifier.java
+++ b/core/src/main/java/org/apache/gravitino/StringIdentifier.java
@@ -176,12 +176,21 @@ public class StringIdentifier {
       return null;
     }
 
-    int index = comment.lastIndexOf('(');
-    if (index == -1) {
+    int left = comment.lastIndexOf('(');
+    int right = comment.lastIndexOf(')');
+    if (left == -1 || right == -1) {
+      return null;
+    }
+    String innerComment = comment.substring(left + 1, right);
+    if (!innerComment.startsWith(STRING_COMMENT)) {
+      return null;
+    }
+
+    String idString = innerComment.substring(STRING_COMMENT.length());
+    if (idString.isEmpty()) {
       return null;
     }
 
-    String idString = comment.substring(index + STRING_COMMENT.length() + 1, 
comment.length() - 1);
     return fromString(idString);
   }
 
diff --git a/core/src/test/java/org/apache/gravitino/TestStringIdentifier.java 
b/core/src/test/java/org/apache/gravitino/TestStringIdentifier.java
index 3a570993ac..967dac542b 100644
--- a/core/src/test/java/org/apache/gravitino/TestStringIdentifier.java
+++ b/core/src/test/java/org/apache/gravitino/TestStringIdentifier.java
@@ -163,6 +163,18 @@ public class TestStringIdentifier {
     String comment1 = "This is a comment";
     StringIdentifier stringIdFromComment2 = 
StringIdentifier.fromComment(comment1);
     Assertions.assertNull(stringIdFromComment2);
+
+    // Test comment contains parentheses but not the Gravitino prefix
+    String comment2 = "This is a comment (other info)";
+    Assertions.assertNull(StringIdentifier.fromComment(comment2));
+
+    // Test comment contains parentheses and Gravitino prefix but not the id
+    String comment3 = "This is a comment (From Gravitino, DO NOT EDIT: )";
+    Assertions.assertNull(StringIdentifier.fromComment(comment3));
+
+    // Test comment where there is no space between Gravitino prefix and id
+    String comment4 = "This is a comment (From Gravitino, DO NOT 
EDIT:gravitino.v1.uid123123)";
+    Assertions.assertNull(StringIdentifier.fromComment(comment4));
   }
 
   @Test

Reply via email to