You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by vi...@apache.org on 2015/12/07 12:19:41 UTC

svn commit: r1718308 - in /tomcat/trunk: java/org/apache/catalina/startup/ContextConfig.java res/findbugs/filter-false-positives.xml

Author: violetagg
Date: Mon Dec  7 11:19:41 2015
New Revision: 1718308

URL: http://svn.apache.org/viewvc?rev=1718308&view=rev
Log:
Fixed some finbugs issues. Mark others as false positive.

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
    tomcat/trunk/res/findbugs/filter-false-positives.xml

Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1718308&r1=1718307&r2=1718308&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Mon Dec  7 11:19:41 2015
@@ -1226,10 +1226,8 @@ public class ContextConfig implements Li
             // Spec does not define an order.
             // Use ordered JARs followed by remaining JARs
             Set<WebXml> resourceJars = new LinkedHashSet<>();
-            if (orderedFragments != null) {
-                for (WebXml fragment : orderedFragments) {
-                    resourceJars.add(fragment);
-                }
+            for (WebXml fragment : orderedFragments) {
+                resourceJars.add(fragment);
             }
             for (WebXml fragment : fragments.values()) {
                 if (!resourceJars.contains(fragment)) {
@@ -1784,44 +1782,47 @@ public class ContextConfig implements Li
 
         // Open the application web.xml file, if it exists
         ServletContext servletContext = context.getServletContext();
-        if (servletContext != null) {
-            altDDName = (String)servletContext.getAttribute(Globals.ALT_DD_ATTR);
-            if (altDDName != null) {
-                try {
-                    stream = new FileInputStream(altDDName);
-                    url = new File(altDDName).toURI().toURL();
-                } catch (FileNotFoundException e) {
-                    log.error(sm.getString("contextConfig.altDDNotFound",
-                                           altDDName));
-                } catch (MalformedURLException e) {
-                    log.error(sm.getString("contextConfig.applicationUrl"));
+        try {
+            if (servletContext != null) {
+                altDDName = (String)servletContext.getAttribute(Globals.ALT_DD_ATTR);
+                if (altDDName != null) {
+                    try {
+                        stream = new FileInputStream(altDDName);
+                        url = new File(altDDName).toURI().toURL();
+                    } catch (FileNotFoundException e) {
+                        log.error(sm.getString("contextConfig.altDDNotFound",
+                                               altDDName));
+                    } catch (MalformedURLException e) {
+                        log.error(sm.getString("contextConfig.applicationUrl"));
+                    }
                 }
-            }
-            else {
-                stream = servletContext.getResourceAsStream
-                    (Constants.ApplicationWebXml);
-                try {
-                    url = servletContext.getResource(
-                            Constants.ApplicationWebXml);
-                } catch (MalformedURLException e) {
-                    log.error(sm.getString("contextConfig.applicationUrl"));
+                else {
+                    stream = servletContext.getResourceAsStream
+                        (Constants.ApplicationWebXml);
+                    try {
+                        url = servletContext.getResource(
+                                Constants.ApplicationWebXml);
+                    } catch (MalformedURLException e) {
+                        log.error(sm.getString("contextConfig.applicationUrl"));
+                    }
                 }
             }
-        }
-        if (stream == null || url == null) {
-            if (log.isDebugEnabled()) {
-                log.debug(sm.getString("contextConfig.applicationMissing") + " " + context);
+            if (stream == null || url == null) {
+                if (log.isDebugEnabled()) {
+                    log.debug(sm.getString("contextConfig.applicationMissing") + " " + context);
+                }
+            } else {
+                source = new InputSource(url.toExternalForm());
+                source.setByteStream(stream);
             }
-            if (stream != null) {
+        } finally {
+            if (source == null && stream != null) {
                 try {
                     stream.close();
                 } catch (IOException e) {
                     // Ignore
                 }
             }
-        } else {
-            source = new InputSource(url.toExternalForm());
-            source.setByteStream(stream);
         }
 
         return source;
@@ -1863,6 +1864,14 @@ public class ContextConfig implements Li
         } catch (Exception e) {
             log.error(sm.getString(
                     "contextConfig.defaultError", filename, file), e);
+        } finally {
+            if (source == null && stream != null) {
+                try {
+                    stream.close();
+                } catch (IOException e) {
+                    // Ignore
+                }
+            }
         }
 
         return source;

Modified: tomcat/trunk/res/findbugs/filter-false-positives.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/res/findbugs/filter-false-positives.xml?rev=1718308&r1=1718307&r2=1718308&view=diff
==============================================================================
--- tomcat/trunk/res/findbugs/filter-false-positives.xml (original)
+++ tomcat/trunk/res/findbugs/filter-false-positives.xml Mon Dec  7 11:19:41 2015
@@ -145,6 +145,15 @@
     <Bug code="Dm" />
   </Match>
   <Match>
+    <!-- The stream is closed in WebXmlParser.parseWebXml -->
+    <Class name="org.apache.catalina.startup.ContextConfig" />
+    <Or>
+      <Method name="getContextWebXmlSource" />
+      <Method name="getWebXmlSource" />
+    </Or>
+    <Bug code="OBL" />
+  </Match>
+  <Match>
     <!-- Sleep is short, needs to keep lock -->
     <Class name="org.apache.catalina.startup.HostConfig" />
     <Method name="checkResources" />
@@ -335,6 +344,12 @@
     <Bug code="DLS"/>
   </Match>
   <Match>
+    <!-- Use of == is deliberate -->
+    <Class name="org.apache.jasper.compiler.Parser"/>
+    <Method name="parseBody"/>
+    <Bug code="ES"/>
+  </Match>
+  <Match>
     <!-- Simpler to catch Exception than to create dummy implementations of the
          necessary exception hierarchy -->
     <Class name="org.apache.naming.factory.SendMailFactory$1" />



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