Rewrite to avoid (im)possible NPE warning

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1478506 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2013-05-02 19:53:15 +00:00
parent d1350bf73f
commit 1a7e46f430
1 changed files with 9 additions and 8 deletions

View File

@ -1486,19 +1486,20 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
* @return this, to enable chaining
* @throws IndexOutOfBoundsException if the index is invalid
*/
@SuppressWarnings("null") // str cannot be null
public StrBuilder insert(final int index, String str) {
validateIndex(index);
if (str == null) {
str = nullText;
}
final int strLen = (str == null ? 0 : str.length());
if (str != null) {
final int strLen = str.length();
if (strLen > 0) {
final int newSize = size + strLen;
ensureCapacity(newSize);
System.arraycopy(buffer, index, buffer, index + strLen, size - index);
size = newSize;
str.getChars(0, strLen, buffer, index); // str cannot be null here
str.getChars(0, strLen, buffer, index);
}
}
return this;
}