diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/text/StrJoiner.java b/hutool-core/src/main/java/org/dromara/hutool/core/text/StrJoiner.java index e6f0c121f..a686a5437 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/text/StrJoiner.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/text/StrJoiner.java @@ -379,7 +379,7 @@ public class StrJoiner implements Appendable, Serializable { * @since 5.7.22 */ public int length() { - return (this.appendable != null ? this.appendable.toString().length() + suffix.length() : + return (this.appendable != null ? this.appendable.toString().length() + StrUtil.length(suffix) : null == this.emptyResult ? -1 : emptyResult.length()); } diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/text/StrJoinerTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/text/StrJoinerTest.java index 343c5c7ef..d1c26f693 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/text/StrJoinerTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/text/StrJoinerTest.java @@ -111,4 +111,13 @@ public class StrJoinerTest { final StrJoiner merge = joiner1.merge(joiner2); Assertions.assertEquals("[123,456,789]", merge.toString()); } + + @Test + void issue3444Test() { + final StrJoiner strJoinerEmpty = StrJoiner.of(","); + Assertions.assertEquals(0, strJoinerEmpty.length()); + + final StrJoiner strJoinerWithContent = StrJoiner.of(",").append("haha"); + Assertions.assertEquals(4, strJoinerWithContent.length()); + } }