Fix "potential null pointer access warning".
authorkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 4 Jul 2011 13:29:44 +0000 (13:29 +0000)
committerkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 4 Jul 2011 13:29:44 +0000 (13:29 +0000)
As a bonus, it avoids allocating char[] buffer for an empty string.
Add $FALL-THROUGH$ comment where we fall through to the next label in switch().

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1142656 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/util/DOMWriter.java

index a5ec657..caa1399 100644 (file)
@@ -290,9 +290,13 @@ public class DOMWriter {
 
    /** Normalizes the given string. */
    protected String normalize(String s) {
+      if (s == null) {
+         return "";
+      }
+
       StringBuilder str = new StringBuilder();
 
-      int len = (s != null) ? s.length() : 0;
+      int len = s.length();
       for ( int i = 0; i < len; i++ ) {
          char ch = s.charAt(i);
          switch ( ch ) {
@@ -322,6 +326,7 @@ public class DOMWriter {
                   }
                   // else, default append char
                }
+            //$FALL-THROUGH$
             default: {
                   str.append(ch);
                }