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 2016/03/22 17:21:49 UTC
svn commit: r1736209 - in /tomcat/trunk:
java/org/apache/tomcat/util/file/ConfigFileLoader.java
java/org/apache/tomcat/util/file/LocalStrings.properties
webapps/docs/changelog.xml
Author: violetagg
Date: Tue Mar 22 16:21:49 2016
New Revision: 1736209
URL: http://svn.apache.org/viewvc?rev=1736209&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=59206
Ensure NPE will not be thrown by when catalina.base is not specified.
Added:
tomcat/trunk/java/org/apache/tomcat/util/file/LocalStrings.properties (with props)
Modified:
tomcat/trunk/java/org/apache/tomcat/util/file/ConfigFileLoader.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/tomcat/util/file/ConfigFileLoader.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/file/ConfigFileLoader.java?rev=1736209&r1=1736208&r2=1736209&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/file/ConfigFileLoader.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/file/ConfigFileLoader.java Tue Mar 22 16:21:49 2016
@@ -24,6 +24,8 @@ import java.io.InputStream;
import java.net.URI;
import java.net.URL;
+import org.apache.tomcat.util.res.StringManager;
+
/**
* This class is used to obtain {@link InputStream}s for configuration files
* from a given location String. This allows greater flexibility than these
@@ -31,12 +33,21 @@ import java.net.URL;
*/
public class ConfigFileLoader {
+ private static final StringManager sm = StringManager.getManager(ConfigFileLoader.class
+ .getPackage().getName());
+
private static final File CATALINA_BASE_FILE;
private static final URI CATALINA_BASE_URI;
static {
- CATALINA_BASE_FILE = new File(System.getProperty("catalina.base"));
- CATALINA_BASE_URI = CATALINA_BASE_FILE.toURI();
+ String catalinaBase = System.getProperty("catalina.base");
+ if (catalinaBase != null) {
+ CATALINA_BASE_FILE = new File(catalinaBase);
+ CATALINA_BASE_URI = CATALINA_BASE_FILE.toURI();
+ } else {
+ CATALINA_BASE_FILE = null;
+ CATALINA_BASE_URI = null;
+ }
}
private ConfigFileLoader() {
@@ -72,10 +83,19 @@ public class ConfigFileLoader {
// File didn't work so try URI.
// Using resolve() enables the code to handle relative paths that did
// not point to a file
- URI uri = CATALINA_BASE_URI.resolve(location);
+ URI uri;
+ if (CATALINA_BASE_URI != null) {
+ uri = CATALINA_BASE_URI.resolve(location);
+ } else {
+ uri = URI.create(location);
+ }
// Obtain the input stream we need
- URL url = uri.toURL();
- return url.openConnection().getInputStream();
+ try {
+ URL url = uri.toURL();
+ return url.openConnection().getInputStream();
+ } catch (IllegalArgumentException e) {
+ throw new IOException(sm.getString("configFileLoader.cannotObtainURL", location), e);
+ }
}
}
Added: tomcat/trunk/java/org/apache/tomcat/util/file/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/file/LocalStrings.properties?rev=1736209&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/file/LocalStrings.properties (added)
+++ tomcat/trunk/java/org/apache/tomcat/util/file/LocalStrings.properties Tue Mar 22 16:21:49 2016
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+configFileLoader.cannotObtainURL=Cannot obtain URL for the relative path [{0}]. Check that catalina.base is set.
\ No newline at end of file
Propchange: tomcat/trunk/java/org/apache/tomcat/util/file/LocalStrings.properties
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1736209&r1=1736208&r2=1736209&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Mar 22 16:21:49 2016
@@ -52,6 +52,11 @@
date formatting in Tomcat's internal request object. Based on a patch
provided by Ondrej Medek. (markt)
</fix>
+ <fix>
+ <bug>59206</bug>: Ensure NPE will not be thrown by
+ <code>o.a.tomcat.util.file.ConfigFileLoader</code> when
+ <code>catalina.base</code> is not specified. (violetagg)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org