diff --git a/tarantool-core/src/main/java/io/tarantool/core/protocol/IProtoResponseImpl.java b/tarantool-core/src/main/java/io/tarantool/core/protocol/IProtoResponseImpl.java index a0dcfe18..98a4f05c 100644 --- a/tarantool-core/src/main/java/io/tarantool/core/protocol/IProtoResponseImpl.java +++ b/tarantool-core/src/main/java/io/tarantool/core/protocol/IProtoResponseImpl.java @@ -21,7 +21,6 @@ public class IProtoResponseImpl implements IProtoMessage { - private StringBuilder stringBuilder; protected MapValue header; protected MapValue body; protected Map headerMap; @@ -51,19 +50,13 @@ protected static Map convertMap(MapValue map) { @Override public String toString() { - if (this.stringBuilder == null) { - this.stringBuilder = new StringBuilder(); - } - - this.stringBuilder.append("IProtoResponseImpl(header = ").append(getHeader().toJson()); + String result = "IProtoResponseImpl(header = " + getHeader().toJson(); if (getBody() != null) { - this.stringBuilder.append(", body = ").append(getBody().toJson()); + result += ", body = " + getBody().toJson(); } - this.stringBuilder.append(")"); - - return this.stringBuilder.toString(); + return result + ")"; } @Override diff --git a/tarantool-core/src/test/java/io/tarantool/core/unit/protocol/IProtoResponseImplTest.java b/tarantool-core/src/test/java/io/tarantool/core/unit/protocol/IProtoResponseImplTest.java new file mode 100644 index 00000000..383f0c03 --- /dev/null +++ b/tarantool-core/src/test/java/io/tarantool/core/unit/protocol/IProtoResponseImplTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2026 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY + * All Rights Reserved. + */ + +package io.tarantool.core.unit.protocol; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.msgpack.value.ValueFactory; + +import static io.tarantool.core.protocol.requests.IProtoConstant.MP_IPROTO_REQUEST_TYPE; +import io.tarantool.core.protocol.IProtoResponseImpl; + +public class IProtoResponseImplTest { + + @Test + public void testToStringDoesNotDuplicateOnRepeatedCalls() { + IProtoResponseImpl response = + new IProtoResponseImpl( + ValueFactory.newMap(MP_IPROTO_REQUEST_TYPE, ValueFactory.newInteger(0)), + ValueFactory.emptyMap()); + + String first = response.toString(); + String second = response.toString(); + + assertTrue(first.startsWith("IProtoResponseImpl(header = ")); + assertEquals(first, second); + } +}