commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1478506 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
Date Thu, 02 May 2013 19:53:18 GMT
Author: sebb
Date: Thu May  2 19:53:15 2013
New Revision: 1478506

URL: http://svn.apache.org/r1478506
Log:
Rewrite to avoid (im)possible NPE warning

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrBuilder.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrBuilder.java?rev=1478506&r1=1478505&r2=1478506&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
Thu May  2 19:53:15 2013
@@ -1486,19 +1486,20 @@ public class StrBuilder implements CharS
      * @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;
     }



Mime
View raw message