You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/04/15 07:49:30 UTC

[GitHub] [rocketmq] shenshaoming opened a new issue #2814: Why the RouteInfoManager.java use nested try...catch

shenshaoming opened a new issue #2814:
URL: https://github.com/apache/rocketmq/issues/2814


   Just as the topic said.I don't know why the code use nested try...catch, maybe because unlock operation can throw an exception?
   The example code is there: 
   
   ### Now
   ```
       public byte[] getAllTopicList() {
           TopicList topicList = new TopicList();
           try {
               try {
                   this.lock.readLock().lockInterruptibly();
                   topicList.getTopicList().addAll(this.topicQueueTable.keySet());
               } finally {
                   this.lock.readLock().unlock();
               }
           } catch (Exception e) {
               log.error("getAllTopicList Exception", e);
           }
   
           return topicList.encode();
       }
   ```
   
   
   ### Expected
   ```
       public byte[] getAllTopicList() {
           TopicList topicList = new TopicList();
           try {
               this.lock.readLock().lockInterruptibly();
               topicList.getTopicList().addAll(this.topicQueueTable.keySet());
           } catch (Exception e) {
               log.error("getAllTopicList Exception", e);
           } finally {
               this.lock.readLock().unlock();
           }
           return topicList.encode();
       }
   ```


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] shenshaoming commented on issue #2814: Why the RouteInfoManager.java use nested try...catch

Posted by GitBox <gi...@apache.org>.
shenshaoming commented on issue #2814:
URL: https://github.com/apache/rocketmq/issues/2814#issuecomment-823171412


   > > getAllTopicList
   > 
   > I agree with u, unlock can throw exception indeed.
   
   Yes, you were right about this. The unlock method will throw an Exception if current thread didn't obtain the lock, which means some exception happens when call the lock method.
   Thank you for your replay.
   


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] lizhiboo commented on issue #2814: Why the RouteInfoManager.java use nested try...catch

Posted by GitBox <gi...@apache.org>.
lizhiboo commented on issue #2814:
URL: https://github.com/apache/rocketmq/issues/2814#issuecomment-822464210


   > getAllTopicList
   
   I agree with u, unlock can throw exception indeed.


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] shenshaoming closed issue #2814: Why the RouteInfoManager.java use nested try...catch

Posted by GitBox <gi...@apache.org>.
shenshaoming closed issue #2814:
URL: https://github.com/apache/rocketmq/issues/2814


   


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org