Add some NPE protection

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

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

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1485855 13f79535-47bb-0310-9956-ffa450edef68
Make this public to expand how the class can be used for unit tests.

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