Author: kkolinko
Date: Sun Jan 17 23:41:04 2016
New Revision: 1725150

URL: http://svn.apache.org/viewvc?rev=1725150&view=rev
Log:
Small code improvements in HostConfig class:

1) In deployWAR() call digester.reset() first before doing non-trivial work 
such as "new URL(...)",
because digester is a shared instance. Though a failure in the "new URL()" call 
there is very unlikely.

2) Reduce scope of "JarEntry entry" variable, getting rid of 
"finally{entry=null;}" blocks.
Anyway a JarEntry is available only while the original JarFile is open.

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1725150&r1=1725149&r2=1725150&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java Sun Jan 17 
23:41:04 2016
@@ -549,10 +549,10 @@ public class HostConfig implements Lifec
                             "hostConfig.deployDescriptor.error",
                             contextXml.getAbsolutePath()), e);
                 } finally {
+                    digester.reset();
                     if (context == null) {
                         context = new FailedContext();
                     }
-                    digester.reset();
                 }
             }
 
@@ -798,16 +798,13 @@ public class HostConfig implements Lifec
                 cn.getBaseName() + "/" + Constants.WarTracker);
 
         boolean xmlInWar = false;
-        JarEntry entry = null;
         try (JarFile jar = new JarFile(war)) {
-            entry = jar.getJarEntry(Constants.ApplicationContextXml);
+            JarEntry entry = jar.getJarEntry(Constants.ApplicationContextXml);
             if (entry != null) {
                 xmlInWar = true;
             }
         } catch (IOException e) {
             /* Ignore */
-        } finally {
-            entry = null;
         }
 
         // If there is an expanded directory then any xml in that directory
@@ -832,17 +829,17 @@ public class HostConfig implements Lifec
                                 "hostConfig.deployDescriptor.error",
                                 war.getAbsolutePath()), e);
                     } finally {
+                        digester.reset();
                         if (context == null) {
                             context = new FailedContext();
                         }
-                        digester.reset();
                     }
                 }
                 context.setConfigFile(xml.toURI().toURL());
             } else if (deployXML && xmlInWar) {
                 synchronized (digesterLock) {
                     try (JarFile jar = new JarFile(war)) {
-                        entry = 
jar.getJarEntry(Constants.ApplicationContextXml);
+                        JarEntry entry = 
jar.getJarEntry(Constants.ApplicationContextXml);
                         try (InputStream istream = jar.getInputStream(entry)) {
                             context = (Context) digester.parse(istream);
                         }
@@ -851,14 +848,13 @@ public class HostConfig implements Lifec
                                 "hostConfig.deployDescriptor.error",
                                 war.getAbsolutePath()), e);
                     } finally {
+                        digester.reset();
                         if (context == null) {
                             context = new FailedContext();
                         }
                         context.setConfigFile(new URL("jar:" +
                                 war.toURI().toString() + "!/" +
                                 Constants.ApplicationContextXml));
-                        entry = null;
-                        digester.reset();
                     }
                 }
             } else if (!deployXML && xmlInWar) {
@@ -895,9 +891,8 @@ public class HostConfig implements Lifec
                 // Change location of XML file to config base
                 xml = new File(host.getConfigBaseFile(),
                         cn.getBaseName() + ".xml");
-                entry = null;
                 try (JarFile jar = new JarFile(war)) {
-                    entry = jar.getJarEntry(Constants.ApplicationContextXml);
+                    JarEntry entry = 
jar.getJarEntry(Constants.ApplicationContextXml);
                     try (InputStream istream = jar.getInputStream(entry);
                             FileOutputStream fos = new FileOutputStream(xml);
                             BufferedOutputStream ostream = new 
BufferedOutputStream(fos, 1024)) {
@@ -1071,10 +1066,10 @@ public class HostConfig implements Lifec
                                 xml), e);
                         context = new FailedContext();
                     } finally {
+                        digester.reset();
                         if (context == null) {
                             context = new FailedContext();
                         }
-                        digester.reset();
                     }
                 }
 

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1725150&r1=1725149&r2=1725150&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Sun Jan 17 23:41:04 2016
@@ -184,6 +184,10 @@
         processing a forwarded request where the target includes a query string
         that contains a parameter with no value. (markt/kkolinko)
       </fix>
+      <fix>
+        Make sure that shared Digester is reset in an unlikely error case
+        in <code>HostConfig.deployWAR()</code>. (kkolinko)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to