This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 4fa6a00a582ed6726451e71ac8f76e868631cb98
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Dec 1 20:35:35 2017 +0000

    Address a few more SpotBugs warnings
---
 java/org/apache/catalina/startup/ExpandWar.java           | 13 ++++++++++---
 java/org/apache/catalina/startup/LocalStrings.properties  |  3 +++
 java/org/apache/catalina/startup/Tomcat.java              |  5 ++++-
 java/org/apache/catalina/util/URLEncoder.java             |  2 +-
 java/org/apache/catalina/valves/rewrite/RewriteValve.java |  8 ++++----
 java/org/apache/el/stream/StreamELResolverImpl.java       |  7 ++++++-
 res/findbugs/filter-false-positives.xml                   | 12 ++++++++++++
 7 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/java/org/apache/catalina/startup/ExpandWar.java 
b/java/org/apache/catalina/startup/ExpandWar.java
index 053464f..7fd7144 100644
--- a/java/org/apache/catalina/startup/ExpandWar.java
+++ b/java/org/apache/catalina/startup/ExpandWar.java
@@ -166,15 +166,22 @@ public class ExpandWar {
                     expand(input, expandedFile);
                     long lastModified = jarEntry.getTime();
                     if ((lastModified != -1) && (lastModified != 0)) {
-                        expandedFile.setLastModified(lastModified);
+                        if (!expandedFile.setLastModified(lastModified)) {
+                            throw new IOException(
+                                    
sm.getString("expandWar.lastModifiedFailed", expandedFile));
+                        }
                     }
                 }
             }
 
             // Create the warTracker file and align the last modified time
             // with the last modified time of the WAR
-            warTracker.createNewFile();
-            warTracker.setLastModified(warLastModified);
+            if (!warTracker.createNewFile()) {
+                throw new 
IOException(sm.getString("expandWar.createFileFailed", warTracker));
+            }
+            if (!warTracker.setLastModified(warLastModified)) {
+                throw new 
IOException(sm.getString("expandWar.lastModifiedFailed", warTracker));
+            }
 
             success = true;
         } catch (IOException e) {
diff --git a/java/org/apache/catalina/startup/LocalStrings.properties 
b/java/org/apache/catalina/startup/LocalStrings.properties
index a55f45d..8b1a617 100644
--- a/java/org/apache/catalina/startup/LocalStrings.properties
+++ b/java/org/apache/catalina/startup/LocalStrings.properties
@@ -87,9 +87,11 @@ engineConfig.stop=EngineConfig: Processing STOP
 
 expandWar.copy=Error copying [{0}] to [{1}]
 expandWar.createFailed=Unable to create the directory [{0}]
+expandWar.createFileFailed=Unable to create the file [{0}]
 expandWar.deleteFailed=[{0}] could not be completely deleted. The presence of 
the remaining files may cause problems
 expandWar.deleteOld=An expanded directory [{0}] was found with a last modified 
time that did not match the associated WAR. It will be deleted.
 expandWar.illegalPath=The archive [{0}] is malformed and will be ignored: an 
entry contains an illegal path [{1}] which was not expanded to [{2}] since that 
is outside of the defined docBase [{3}]
+expandWar.lastModifiedFailed=Unable to set the last modified time for [{0}]
 expandWar.missingJarEntry=Cannot get input stream for JarEntry [{0}] - broken 
WAR file?
 
 failedContext.start=Failed to process either the global, per-host or 
context-specific context.xml file therefore the [{0}] Context cannot be started.
@@ -136,6 +138,7 @@ passwdUserDatabase.readFail=Failed to obtain a complete set 
of users from /etc/p
 
 tomcat.addWebapp.conflictChild=Unable to deploy WAR at [{0}] to context path 
[{1}] because of existing context [{2}]
 tomcat.addWebapp.conflictFile=Unable to deploy WAR at [{0}] to context path 
[{1}] because of existing file [{2}]
+tomcat.homeDirMakeFail=Unable to create the directory [{0}] to use as the home 
directory
 
 userConfig.database=Exception loading user database
 userConfig.deploy=Deploying web application for user [{0}]
diff --git a/java/org/apache/catalina/startup/Tomcat.java 
b/java/org/apache/catalina/startup/Tomcat.java
index 5102a37..297f1f4 100644
--- a/java/org/apache/catalina/startup/Tomcat.java
+++ b/java/org/apache/catalina/startup/Tomcat.java
@@ -808,7 +808,10 @@ public class Tomcat {
             server.setCatalinaHome(baseFile);
         } else {
             File homeFile = new File(catalinaHome);
-            homeFile.mkdirs();
+            if (!homeFile.isDirectory() && !homeFile.mkdirs()) {
+                // Failed to create home directory
+                throw new 
IllegalStateException(sm.getString("tomcat.homeDirMakeFail", homeFile));
+            }
             try {
                 homeFile = homeFile.getCanonicalFile();
             } catch (IOException e) {
diff --git a/java/org/apache/catalina/util/URLEncoder.java 
b/java/org/apache/catalina/util/URLEncoder.java
index e1ecfc4..5f630e0 100644
--- a/java/org/apache/catalina/util/URLEncoder.java
+++ b/java/org/apache/catalina/util/URLEncoder.java
@@ -37,7 +37,7 @@ import org.apache.tomcat.util.buf.B2CConverter;
  * @author Craig R. McClanahan
  * @author Remy Maucherat
  */
-public class URLEncoder implements Cloneable {
+public final class URLEncoder implements Cloneable {
 
     private static final char[] hexadecimal =
             {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 
'D', 'E', 'F'};
diff --git a/java/org/apache/catalina/valves/rewrite/RewriteValve.java 
b/java/org/apache/catalina/valves/rewrite/RewriteValve.java
index 284a585..5b719ba 100644
--- a/java/org/apache/catalina/valves/rewrite/RewriteValve.java
+++ b/java/org/apache/catalina/valves/rewrite/RewriteValve.java
@@ -554,18 +554,18 @@ public class RewriteValve extends ValveBase {
                     }
                     request.getMappingData().recycle();
                     // Reinvoke the whole request recursively
+                    Connector connector = request.getConnector();
                     try {
-                        Connector connector = request.getConnector();
                         if 
(!connector.getProtocolHandler().getAdapter().prepare(
                                 request.getCoyoteRequest(), 
response.getCoyoteResponse())) {
                             return;
                         }
-                        Pipeline pipeline = 
connector.getService().getContainer().getPipeline();
-                        request.setAsyncSupported(pipeline.isAsyncSupported());
-                        pipeline.getFirst().invoke(request, response);
                     } catch (Exception e) {
                         // This doesn't actually happen in the Catalina 
adapter implementation
                     }
+                    Pipeline pipeline = 
connector.getService().getContainer().getPipeline();
+                    request.setAsyncSupported(pipeline.isAsyncSupported());
+                    pipeline.getFirst().invoke(request, response);
                 }
             } else {
                 getNext().invoke(request, response);
diff --git a/java/org/apache/el/stream/StreamELResolverImpl.java 
b/java/org/apache/el/stream/StreamELResolverImpl.java
index d76dd7e..f5f6bcf 100644
--- a/java/org/apache/el/stream/StreamELResolverImpl.java
+++ b/java/org/apache/el/stream/StreamELResolverImpl.java
@@ -20,6 +20,7 @@ import java.beans.FeatureDescriptor;
 import java.lang.reflect.Array;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.NoSuchElementException;
 
 import javax.el.ELContext;
 import javax.el.ELResolver;
@@ -97,7 +98,11 @@ public class StreamELResolverImpl extends ELResolver {
 
         @Override
         public Object next() {
-            return Array.get(base, index++);
+            try {
+                return Array.get(base, index++);
+            } catch (ArrayIndexOutOfBoundsException e) {
+                throw new NoSuchElementException();
+            }
         }
 
         @Override
diff --git a/res/findbugs/filter-false-positives.xml 
b/res/findbugs/filter-false-positives.xml
index d8bed9f..f441fdf 100644
--- a/res/findbugs/filter-false-positives.xml
+++ b/res/findbugs/filter-false-positives.xml
@@ -340,6 +340,12 @@
     <Bug code="Dm" />
   </Match>
   <Match>
+    <!-- Failure at this point is fatal -->
+    <Class name="org.apache.catalina.startup.Bootstrap" />
+    <Method name="initClassLoaders" />
+    <Bug pattern="DM_EXIT" />
+  </Match>
+  <Match>
     <!-- Catalina isn't used when embedding -->
     <Class name="org.apache.catalina.startup.Catalina" />
     <Method name="stopServer" />
@@ -355,6 +361,12 @@
     <Bug code="OBL" />
   </Match>
   <Match>
+    <!-- Method checks result and logs error later -->
+    <Class name="org.apache.catalina.startup.ExpandWar" />
+    <Method name="deleteDir" />
+    <Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
+  </Match>
+  <Match>
     <!-- Sleep is short, needs to keep lock -->
     <Class name="org.apache.catalina.startup.HostConfig" />
     <Method name="checkResources" />


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

Reply via email to