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:
[email protected]


Reply via email to