diff --git a/src/java/org/apache/commons/lang/text/StrBuilder.java b/src/java/org/apache/commons/lang/text/StrBuilder.java index b0b46228f..6b7dbf632 100644 --- a/src/java/org/apache/commons/lang/text/StrBuilder.java +++ b/src/java/org/apache/commons/lang/text/StrBuilder.java @@ -589,10 +589,11 @@ public class StrBuilder implements Cloneable { if (coll != null && coll.size() > 0) { separator = (separator == null ? "" : separator); Iterator it = coll.iterator(); - append(it.next()); while (it.hasNext()) { - append(separator); append(it.next()); + if (it.hasNext()) { + append(separator); + } } } return this; @@ -611,10 +612,11 @@ public class StrBuilder implements Cloneable { public StrBuilder appendWithSeparators(Iterator it, String separator) { if (it != null) { separator = (separator == null ? "" : separator); - append(it.next()); while (it.hasNext()) { - append(separator); append(it.next()); + if (it.hasNext()) { + append(separator); + } } } return this; diff --git a/src/test/org/apache/commons/lang/text/StrBuilderTest.java b/src/test/org/apache/commons/lang/text/StrBuilderTest.java index 14660268b..87e70c781 100644 --- a/src/test/org/apache/commons/lang/text/StrBuilderTest.java +++ b/src/test/org/apache/commons/lang/text/StrBuilderTest.java @@ -567,7 +567,7 @@ public class StrBuilderTest extends TestCase { sb.clear(); sb.setNullText("null"); - sb.appendFixedWidthPadRight(null, 5, '-'); + sb.appendFixedWidthPadLeft(null, 5, '-'); assertEquals("-null", sb.toString()); }