Bug 46298 - JDBCRealm.open() throws NullPointerException if the specified driver doesn't handle the specified JDBC URL
Summary: JDBCRealm.open() throws NullPointerException if the specified driver doesn't ...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: unspecified
Hardware: All All
: P2 minor (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-25 23:25 UTC by Owen Jacobson
Modified: 2009-01-14 15:58 UTC (History)
0 users



Attachments
Check returned connection for null in JDBCRealm.open() (666 bytes, patch)
2008-11-25 23:25 UTC, Owen Jacobson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Owen Jacobson 2008-11-25 23:25:56 UTC
Created attachment 22949 [details]
Check returned connection for null in JDBCRealm.open()

Per the Driver.connect(String, Properties) docs:

> The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL.

I ran into this when I fat-fingered the JDBC URL's prefix (jdbc:msql: instead of jdbc:mysql: with the MySQL driver).  The offending code calls Driver.connect and immediately calls setAutoCommit(false) on the resulting driver without checking that the connect returned a connection.

I've attached a patch based from TOMCAT_6_0_18 that addresses the issue.
Comment 1 Mark Thomas 2008-12-28 15:49:35 UTC
Thanks for the patch. I have applied a variation to trunk and will propose it for 6.0.x
The changes I made were:
- test dbConnection for null rather than driver (which is always non-null)
- use the StringManager to provide i18n for the exception message
Comment 2 Owen Jacobson 2008-12-28 17:06:48 UTC
Thanks for catching the typo in the patch! Clearly, I fat-finger a lot of things.  I18n is also a nice touch.
Comment 3 Mark Thomas 2009-01-14 15:58:50 UTC
This has been fixed in 6.0.x and will be included in 6.0.19 onwards.