Only prepend hostname if it has text

parent 69fd8e7e
...@@ -7,6 +7,7 @@ import java.lang.reflect.Field; ...@@ -7,6 +7,7 @@ import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonGenerator;
...@@ -133,7 +134,7 @@ public class CloudJacksonJson extends LegacyJacksonJson { ...@@ -133,7 +134,7 @@ public class CloudJacksonJson extends LegacyJacksonJson {
private String calculateInstanceId(InstanceInfo info) { private String calculateInstanceId(InstanceInfo info) {
String instanceId = info.getMetadata().get("instanceId"); String instanceId = info.getMetadata().get("instanceId");
String hostName = info.getHostName(); String hostName = info.getHostName();
if (instanceId != null && !instanceId.startsWith(hostName)) { if (instanceId != null && StringUtils.hasText(hostName) && !instanceId.startsWith(hostName)) {
instanceId = hostName + ":" + instanceId; instanceId = hostName + ":" + instanceId;
} }
return instanceId == null ? hostName : instanceId; return instanceId == null ? hostName : instanceId;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment