diff --git a/core/src/main/java/com/linecorp/armeria/client/Endpoint.java b/core/src/main/java/com/linecorp/armeria/client/Endpoint.java index c33418f6d9f..bb100b9a004 100644 --- a/core/src/main/java/com/linecorp/armeria/client/Endpoint.java +++ b/core/src/main/java/com/linecorp/armeria/client/Endpoint.java @@ -232,7 +232,6 @@ enum Type { private final int weight; private final List endpoints; private final String authority; - private final String strVal; @Nullable private final Attributes attributes; @@ -264,8 +263,6 @@ private Endpoint(Type type, String host, @Nullable String ipAddr, int port, int // Pre-generate the authority. authority = generateAuthority(type, host, port); - // Pre-generate toString() value. - strVal = generateToString(type, authority, ipAddr, weight, attributes); this.attributes = attributes; } @@ -291,22 +288,6 @@ private static String generateAuthority(Type type, String host, int port) { } } - private static String generateToString(Type type, String authority, @Nullable String ipAddr, - int weight, @Nullable Attributes attributes) { - try (TemporaryThreadLocals tempThreadLocals = TemporaryThreadLocals.acquire()) { - final StringBuilder buf = tempThreadLocals.stringBuilder(); - buf.append("Endpoint{").append(authority); - if (type == Type.HOSTNAME_AND_IP) { - buf.append(", ipAddr=").append(ipAddr); - } - buf.append(", weight=").append(weight); - if (attributes != null) { - buf.append(", attributes=").append(attributes); - } - return buf.append('}').toString(); - } - } - @Override public List endpoints() { return endpoints; @@ -981,6 +962,14 @@ public int compareTo(Endpoint that) { @Override public String toString() { - return strVal; + try (TemporaryThreadLocals tempThreadLocals = TemporaryThreadLocals.acquire()) { + final StringBuilder buf = tempThreadLocals.stringBuilder(); + buf.append("Endpoint{").append(authority); + if (type == Type.HOSTNAME_AND_IP) { + buf.append(", ipAddr=").append(ipAddr); + } + return buf.append(", weight=").append(weight) + .append('}').toString(); + } } } diff --git a/core/src/test/java/com/linecorp/armeria/client/EndpointTest.java b/core/src/test/java/com/linecorp/armeria/client/EndpointTest.java index 31c815d1f80..606069d006f 100644 --- a/core/src/test/java/com/linecorp/armeria/client/EndpointTest.java +++ b/core/src/test/java/com/linecorp/armeria/client/EndpointTest.java @@ -539,8 +539,9 @@ void testToString() { // attributes final Endpoint endpointWithAttr = Endpoint.of("127.0.0.1").withAttr(AttributeKey.valueOf("test"), 1); + // toString() should not include the attributes. assertThat(endpointWithAttr.toString()) - .isEqualTo("Endpoint{127.0.0.1, weight=1000, attributes=[test=1]}"); + .isEqualTo("Endpoint{127.0.0.1, weight=1000}"); } @Test