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 2020/05/11 09:51:59 UTC

[GitHub] [rocketmq] RongtongJin commented on a change in pull request #1981: [ISSUE #1978] Fix issue that MessageExt#getBornHostString throw NPE

RongtongJin commented on a change in pull request #1981:
URL: https://github.com/apache/rocketmq/pull/1981#discussion_r422921314



##########
File path: common/src/main/java/org/apache/rocketmq/common/message/MessageExt.java
##########
@@ -118,18 +118,25 @@ public void setBornHost(SocketAddress bornHost) {
     }
 
     public String getBornHostString() {
-        if (this.bornHost != null) {
-            InetSocketAddress inetSocketAddress = (InetSocketAddress) this.bornHost;
-            return inetSocketAddress.getAddress().getHostAddress();
+        try {
+            if (this.bornHost != null) {
+                InetSocketAddress inetSocketAddress = (InetSocketAddress) this.bornHost;
+                return inetSocketAddress.getAddress().getHostAddress();
+            }
+        } catch (Exception e) {
         }
 
         return null;
     }
 
     public String getBornHostNameString() {
-        if (this.bornHost != null) {
-            InetSocketAddress inetSocketAddress = (InetSocketAddress) this.bornHost;
-            return inetSocketAddress.getAddress().getHostName();
+        try {
+            if (this.bornHost != null) {
+                InetSocketAddress inetSocketAddress = (InetSocketAddress) this.bornHost;
+                return inetSocketAddress.getAddress().getHostName();
+            }
+        } catch (Exception e) {

Review comment:
       It is recommended to check for NPE in advance instead of catching exceptions




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