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

kfujino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new c5eefc7  Throw SQLException instead of NullpointerException when 
failing to connect to the database
c5eefc7 is described below

commit c5eefc75a84b9f02ac5b50a06b95bcc18537569f
Author: KeiichiFujino <kfuj...@apache.org>
AuthorDate: Thu Sep 24 21:48:52 2020 +0900

    Throw SQLException instead of NullpointerException when failing to connect 
to the database
---
 java/org/apache/catalina/session/JDBCStore.java          | 3 +++
 java/org/apache/catalina/session/LocalStrings.properties | 1 +
 webapps/docs/changelog.xml                               | 5 +++++
 3 files changed, 9 insertions(+)

diff --git a/java/org/apache/catalina/session/JDBCStore.java 
b/java/org/apache/catalina/session/JDBCStore.java
index bb57db0..63370c8 100644
--- a/java/org/apache/catalina/session/JDBCStore.java
+++ b/java/org/apache/catalina/session/JDBCStore.java
@@ -936,6 +936,9 @@ public class JDBCStore extends StoreBase {
         if (connectionPassword != null)
             props.put("password", connectionPassword);
         dbConnection = driver.connect(connectionURL, props);
+        if (dbConnection == null) {
+            throw new SQLException(sm.getString(getStoreName() + 
".connectError", connectionURL));
+        }
         dbConnection.setAutoCommit(true);
         return dbConnection;
 
diff --git a/java/org/apache/catalina/session/LocalStrings.properties 
b/java/org/apache/catalina/session/LocalStrings.properties
index 127cd43..dae4f68 100644
--- a/java/org/apache/catalina/session/LocalStrings.properties
+++ b/java/org/apache/catalina/session/LocalStrings.properties
@@ -25,6 +25,7 @@ JDBCStore.missingDataSourceName=No valid JNDI name was given.
 JDBCStore.removing=Removing Session [{0}] at database [{1}]
 JDBCStore.saving=Saving Session [{0}] to database [{1}]
 JDBCStore.wrongDataSource=Cannot open JNDI DataSource [{0}]
+JDBCStore.connectError=Cannot connect to database [{0}]
 
 fileStore.createFailed=Unable to create directory [{0}] for the storage of 
session data
 fileStore.deleteFailed=Unable to delete file [{0}] which is preventing the 
creation of the session storage location
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a6d3b84..a10d2c3 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -84,6 +84,11 @@
         speed of applications with a large number of JARs. Patch
         provided by Jatin Kamnani. (remm)
       </update>
+      <fix>
+        Throw <code>SQLException</code> instead of
+        <code>NullpointerException</code> when failing to connect to the
+        database. (kfujino)
+      </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