From 4feb8cae0cf3d4432e7a3beb4b48377f1b33e2ae Mon Sep 17 00:00:00 2001 From: lebron374 Date: Mon, 25 May 2020 23:37:50 +0800 Subject: [PATCH] npe fix --- .../apache/rocketmq/common/message/MessageExt.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageExt.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageExt.java index 7f351725..577c4f4b 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageExt.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageExt.java @@ -142,18 +142,20 @@ public class MessageExt extends Message { } public String getBornHostString() { - if (this.bornHost != null) { - InetSocketAddress inetSocketAddress = (InetSocketAddress) this.bornHost; - return inetSocketAddress.getAddress().getHostAddress(); + if (null != this.bornHost) { + InetAddress inetAddress = ((InetSocketAddress) this.bornHost).getAddress(); + + return null != inetAddress ? inetAddress.getHostAddress() : null; } return null; } public String getBornHostNameString() { - if (this.bornHost != null) { - InetSocketAddress inetSocketAddress = (InetSocketAddress) this.bornHost; - return inetSocketAddress.getAddress().getHostName(); + if (null != this.bornHost) { + InetAddress inetAddress = ((InetSocketAddress) this.bornHost).getAddress(); + + return null != inetAddress ? inetAddress.getHostName() : null; } return null; -- GitLab