[tomcat] branch 9.0.x updated: Throw SQLException instead of NullpointerException when failing to connect to the database

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[tomcat] branch 9.0.x updated: Throw SQLException instead of NullpointerException when failing to connect to the database

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

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


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

commit 478ac96b071ff32d4f649469cd88226ea7374680
Author: KeiichiFujino <[hidden email]>
AuthorDate: Thu Sep 24 21:59:42 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 96a0162..6f7f2c6 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -83,6 +83,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: [hidden email]
For additional commands, e-mail: [hidden email]