From: kkolinko Date: Mon, 4 Jul 2011 13:29:44 +0000 (+0000) Subject: Fix "potential null pointer access warning". X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8aaa95eedc0618f1af3ecec6c0ff82f7c5b2c390;p=tomcat7.0 Fix "potential null pointer access warning". 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 --- diff --git a/java/org/apache/catalina/util/DOMWriter.java b/java/org/apache/catalina/util/DOMWriter.java index a5ec657d9..caa13995d 100644 --- a/java/org/apache/catalina/util/DOMWriter.java +++ b/java/org/apache/catalina/util/DOMWriter.java @@ -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); }