RongtongJin commented on a change in pull request #1981:
URL: https://github.com/apache/rocketmq/pull/1981#discussion_r425614127
##########
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 would be better to write as this instead of catching exceptions
```java
public String getBornHostNameString() {
if (this.bornHost != null) {
InetAddress inetAddress = ((InetSocketAddress)
this.bornHost).getAddress();
return inetAddress != null ? inetAddress.getHostName() : null;
}
return null;
}
```
----------------------------------------------------------------
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]