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:
parent
d1350bf73f
commit
1a7e46f430
|
@ -1486,19 +1486,20 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
|
||||||
* @return this, to enable chaining
|
* @return this, to enable chaining
|
||||||
* @throws IndexOutOfBoundsException if the index is invalid
|
* @throws IndexOutOfBoundsException if the index is invalid
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("null") // str cannot be null
|
|
||||||
public StrBuilder insert(final int index, String str) {
|
public StrBuilder insert(final int index, String str) {
|
||||||
validateIndex(index);
|
validateIndex(index);
|
||||||
if (str == null) {
|
if (str == null) {
|
||||||
str = nullText;
|
str = nullText;
|
||||||
}
|
}
|
||||||
final int strLen = (str == null ? 0 : str.length());
|
if (str != null) {
|
||||||
|
final int strLen = str.length();
|
||||||
if (strLen > 0) {
|
if (strLen > 0) {
|
||||||
final int newSize = size + strLen;
|
final int newSize = size + strLen;
|
||||||
ensureCapacity(newSize);
|
ensureCapacity(newSize);
|
||||||
System.arraycopy(buffer, index, buffer, index + strLen, size - index);
|
System.arraycopy(buffer, index, buffer, index + strLen, size - index);
|
||||||
size = newSize;
|
size = newSize;
|
||||||
str.getChars(0, strLen, buffer, index); // str cannot be null here
|
str.getChars(0, strLen, buffer, index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue