justinmclean opened a new issue, #10133:
URL: https://github.com/apache/gravitino/issues/10133

   ### What would you like to be improved?
   
   TopicMetaService#getTopicPOByFullQualifiedName assumes the topic namespace 
always has 3 levels and directly accesses namespaceLevels[0..2]. For malformed 
input (fewer levels), this throws ArrayIndexOutOfBoundsException.
   
   ### How should we improve?
   
   Validate the identifier namespace before indexing. Reuse existing validation 
(NameIdentifierUtil.checkTopic(identifier) or 
NamespaceUtil.checkTopic(identifier.namespace())) at the start of 
getTopicPOByFullQualifiedName (and similarly in listTopicPOsByFullQualifiedName 
if needed). Then convert invalid inputs into a more appropriate exception type, 
possibly NoSuchEntityException.
   
   Here's a unit test to help:
   ```
   public class TestTopicMetaServiceMalformedIdentifier extends TestJDBCBackend 
{
     private final String metalakeName = "metalake_for_topic_test";
     private final String catalogName = "catalog_for_topic_test";
   
     @TestTemplate
     public void 
testGetTopicByFullQualifiedNameMalformedNamespaceThrowsNoSuchEntityException()
         throws Exception {
       Method method =
           TopicMetaService.class.getDeclaredMethod(
               "getTopicPOByFullQualifiedName", NameIdentifier.class);
       method.setAccessible(true);
   
       NameIdentifier malformedIdentifier =
           NameIdentifier.of(Namespace.of(metalakeName, catalogName), "topic");
   
       InvocationTargetException invocationTargetException =
           assertThrows(
               InvocationTargetException.class,
               () -> method.invoke(TopicMetaService.getInstance(), 
malformedIdentifier));
   
       assertInstanceOf(NoSuchEntityException.class, 
invocationTargetException.getCause());
     }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to