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
|
||||
* @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 (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
|
||||
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);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue