Author: markt
Date: Fri Dec 1 20:35:35 2017
New Revision: 1816905
URL: http://svn.apache.org/viewvc?rev=1816905&view=rev
Log:
Address a few more SpotBugs warnings
Modified:
tomcat/trunk/java/org/apache/catalina/startup/ExpandWar.java
tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
tomcat/trunk/java/org/apache/catalina/users/LocalStrings.properties
tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java
tomcat/trunk/java/org/apache/catalina/util/URLEncoder.java
tomcat/trunk/java/org/apache/catalina/valves/rewrite/RewriteValve.java
tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java
tomcat/trunk/res/findbugs/filter-false-positives.xml
Modified: tomcat/trunk/java/org/apache/catalina/startup/ExpandWar.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ExpandWar.java?rev=1816905&r1=1816904&r2=1816905&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ExpandWar.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ExpandWar.java Fri Dec 1
20:35:35 2017
@@ -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) {
Modified: tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=1816905&r1=1816904&r2=1816905&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
(original)
+++ tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties Fri
Dec 1 20:35:35 2017
@@ -81,9 +81,11 @@ engineConfig.start=EngineConfig: Process
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.
hostConfig.appBase=Application base [{1}] for host [{0}] does not exist or is
not a directory. deployOnStartUp and autoDeploy have been set to false to
prevent deployment errors. Other errors may still occur.
@@ -126,6 +128,7 @@ hostConfig.undeployVersion=Undeploying o
passwdUserDatabase.readFail=Failed to obtain a complete set of users from
/etc/passwd
tomcat.baseDirNotDir=The location [{0}] specified for the base directory is
not a directory
tomcat.baseDirMakeFail=Unable to create the directory [{0}] to use as the base
directory
+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}]
userConfig.deploying=Deploying user web applications
Modified: tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java?rev=1816905&r1=1816904&r2=1816905&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java Fri Dec 1
20:35:35 2017
@@ -745,7 +745,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) {
Modified: tomcat/trunk/java/org/apache/catalina/users/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/users/LocalStrings.properties?rev=1816905&r1=1816904&r2=1816905&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/users/LocalStrings.properties
(original)
+++ tomcat/trunk/java/org/apache/catalina/users/LocalStrings.properties Fri Dec
1 20:35:35 2017
@@ -14,6 +14,7 @@
# limitations under the License.
memoryUserDatabase.fileNotFound=The specified user database [{0}] could not be
found
+memoryUserDatabase.fileDelete=Failed to delete [{0}]
memoryUserDatabase.notPersistable=User database is not persistable - no write
permissions on directory
memoryUserDatabase.nullGroup=Null or zero length group name specified. The
group will be ignored.
memoryUserDatabase.nullRole=Null or zero length role name specified. The role
will be ignored.
@@ -21,5 +22,6 @@ memoryUserDatabase.nullUser=Null or zero
memoryUserDatabase.readOnly=User database has been configured to be read only.
Changes cannot be saved
memoryUserDatabase.renameOld=Cannot rename original file to [{0}]
memoryUserDatabase.renameNew=Cannot rename new file to [{0}]
+memoryUserDatabase.restoreOrig=Cannot restore [{0} to original file
memoryUserDatabase.writeException=IOException writing to [{0}]
memoryUserDatabase.xmlFeatureEncoding=Exception configuring digester to permit
java encoding names in XML files. Only IANA encoding names will be supported.
Modified: tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java?rev=1816905&r1=1816904&r2=1816905&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java Fri Dec
1 20:35:35 2017
@@ -504,16 +504,12 @@ public class MemoryUserDatabase implemen
// Write out contents to a temporary file
File fileNew = new File(pathnameNew);
if (!fileNew.isAbsolute()) {
- fileNew =
- new File(System.getProperty(Globals.CATALINA_BASE_PROP),
pathnameNew);
+ fileNew = new File(System.getProperty(Globals.CATALINA_BASE_PROP),
pathnameNew);
}
- PrintWriter writer = null;
- try {
- // Configure our PrintWriter
- FileOutputStream fos = new FileOutputStream(fileNew);
- OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF8");
- writer = new PrintWriter(osw);
+ try (FileOutputStream fos = new FileOutputStream(fileNew);
+ OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF8");
+ PrintWriter writer = new PrintWriter(osw)) {
// Print the file prolog
writer.println("<?xml version='1.0' encoding='utf-8'?>");
@@ -545,51 +541,46 @@ public class MemoryUserDatabase implemen
// Check for errors that occurred while printing
if (writer.checkError()) {
- writer.close();
- fileNew.delete();
- throw new IOException
- (sm.getString("memoryUserDatabase.writeException",
- fileNew.getAbsolutePath()));
+ throw new
IOException(sm.getString("memoryUserDatabase.writeException",
+ fileNew.getAbsolutePath()));
}
- writer.close();
} catch (IOException e) {
- if (writer != null) {
- writer.close();
+ if (fileNew.exists() && !fileNew.delete()) {
+ log.warn(sm.getString("memoryUserDatabase.fileDelete",
fileNew));
}
- fileNew.delete();
throw e;
}
// Perform the required renames to permanently save this file
File fileOld = new File(pathnameOld);
if (!fileOld.isAbsolute()) {
- fileOld =
- new File(System.getProperty(Globals.CATALINA_BASE_PROP),
pathnameOld);
+ fileOld = new File(System.getProperty(Globals.CATALINA_BASE_PROP),
pathnameOld);
+ }
+ if (fileOld.exists() && !fileOld.delete()) {
+ throw new
IOException(sm.getString("memoryUserDatabase.fileDelete", fileOld));
}
- fileOld.delete();
File fileOrig = new File(pathname);
if (!fileOrig.isAbsolute()) {
- fileOrig =
- new File(System.getProperty(Globals.CATALINA_BASE_PROP),
pathname);
+ fileOrig = new
File(System.getProperty(Globals.CATALINA_BASE_PROP), pathname);
}
if (fileOrig.exists()) {
- fileOld.delete();
if (!fileOrig.renameTo(fileOld)) {
- throw new IOException
- (sm.getString("memoryUserDatabase.renameOld",
- fileOld.getAbsolutePath()));
+ throw new
IOException(sm.getString("memoryUserDatabase.renameOld",
+ fileOld.getAbsolutePath()));
}
}
if (!fileNew.renameTo(fileOrig)) {
if (fileOld.exists()) {
- fileOld.renameTo(fileOrig);
+ if (!fileOld.renameTo(fileOrig)) {
+ log.warn(sm.getString("memoryUserDatabase.restoreOrig",
fileOld));
+ }
}
- throw new IOException
- (sm.getString("memoryUserDatabase.renameNew",
- fileOrig.getAbsolutePath()));
+ throw new IOException(sm.getString("memoryUserDatabase.renameNew",
+ fileOrig.getAbsolutePath()));
+ }
+ if (fileOld.exists() && !fileOld.delete()) {
+ throw new
IOException(sm.getString("memoryUserDatabase.fileDelete", fileOld));
}
- fileOld.delete();
-
}
Modified: tomcat/trunk/java/org/apache/catalina/util/URLEncoder.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/URLEncoder.java?rev=1816905&r1=1816904&r2=1816905&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/URLEncoder.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/URLEncoder.java Fri Dec 1
20:35:35 2017
@@ -34,7 +34,7 @@ import java.util.BitSet;
* @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'};
Modified: tomcat/trunk/java/org/apache/catalina/valves/rewrite/RewriteValve.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/rewrite/RewriteValve.java?rev=1816905&r1=1816904&r2=1816905&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/rewrite/RewriteValve.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/valves/rewrite/RewriteValve.java Fri
Dec 1 20:35:35 2017
@@ -523,18 +523,18 @@ public class RewriteValve extends ValveB
}
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);
Modified: tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java?rev=1816905&r1=1816904&r2=1816905&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java (original)
+++ tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java Fri Dec 1
20:35:35 2017
@@ -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 extend
@Override
public Object next() {
- return Array.get(base, index++);
+ try {
+ return Array.get(base, index++);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new NoSuchElementException();
+ }
}
@Override
Modified: tomcat/trunk/res/findbugs/filter-false-positives.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/res/findbugs/filter-false-positives.xml?rev=1816905&r1=1816904&r2=1816905&view=diff
==============================================================================
--- tomcat/trunk/res/findbugs/filter-false-positives.xml (original)
+++ tomcat/trunk/res/findbugs/filter-false-positives.xml Fri Dec 1 20:35:35
2017
@@ -354,6 +354,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" />
@@ -369,6 +375,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: [email protected]
For additional commands, e-mail: [email protected]