Bug 46298

Summary: JDBCRealm.open() throws NullPointerException if the specified driver doesn't handle the specified JDBC URL
Product: Tomcat 6 Reporter: Owen Jacobson <owen.jacobson>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: minor    
Priority: P2    
Version: unspecified   
Target Milestone: default   
Hardware: All   
OS: All   
Attachments: Check returned connection for null in JDBCRealm.open()

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.