修复StrJoin当append内容后调用length()会出现空指针问题

This commit is contained in:
Looly
2023-12-26 00:41:06 +08:00
parent 99303ef7e0
commit ab1b2c5e48
4 changed files with 18 additions and 4 deletions

View File

@@ -357,7 +357,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());
}

View File

@@ -99,4 +99,13 @@ public class StrJoinerTest {
final StrJoiner merge = joiner1.merge(joiner2);
Assert.assertEquals("[123,456,789]", merge.toString());
}
@Test
public void issue3444Test() {
final StrJoiner strJoinerEmpty = StrJoiner.of(",");
Assert.assertEquals(0, strJoinerEmpty.length());
final StrJoiner strJoinerWithContent = StrJoiner.of(",").append("haha");
Assert.assertEquals(4, strJoinerWithContent.length());
}
}