Lucee doesn't correctly handle wrong JDBC connection string, causing NPE

Description

I found this on accident when I manually declared a datasource connection that used the JTDS driver but accidentally used the Microsoft JDBC connection string:

dsources[ "MyDSN" ] = { "class" = "net.sourceforge.jtds.jdbc.Driver", // WRONG CONNECTION STRING "connectionString" = "jdbc:sqlserver://192.168.6.13:1433;DATABASENAME=myDB", "username" = "user", "password" = "pass", "bundleName" = "jtds", "bundleVersion" = "1.3.1" };

The error was a null pointer exception which was unhelpful and difficult to track down.

lucee.runtime.exp.NativeException: java.lang.NullPointerException at lucee.runtime.db.DatasourceConnectionPool.loadDatasourceConnection(DatasourceConnectionPool.java:135) at lucee.runtime.db.DatasourceConnectionPool.getDatasourceConnection(DatasourceConnectionPool.java:101) at lucee.runtime.db.DatasourceManagerImpl.getConnection(DatasourceManagerImpl.java:73) at lucee.runtime.tag.Query.executeDatasoure(Query.java:1043) at lucee.runtime.tag.Query._doEndTag(Query.java:660) at lucee.runtime.tag.Query.doEndTag(Query.java:542) at lucee.runtime.functions.query.QueryExecute.call(QueryExecute.java:86)

If you look at the docs, you'll find this:
https://docs.oracle.com/javase/7/docs/api/java/sql/Driver.html#connect(java.lang.String,%20java.util.Properties)

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

Lucee does not account for getting null back when asking the driver to connect. Lucee needs to check for a null value back and throw an exception that explains that the driver has rejected the connection string. Here is the line of code in Lucee that needs to be doing this check:

https://github.com/lucee/Lucee/blob/master/core/src/main/java/lucee/runtime/db/DataSourceSupport.java#L111

Environment

None

Activity

Show:

Pothys - MitrahSoft 4 April 2023 at 11:50
Edited

I checked this issue with lucee latest build 6.0.0.360-snapshot. When using an invalid connection string in a datasource it throws an error such as Unable to validate object.

Stacktrace for lucee 6.0:

lucee.runtime.exp.NativeException: Unable to validate object at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:493) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:356) at lucee.runtime.config.DatasourceConnPool.borrowObject(DatasourceConnPool.java:30) at lucee.runtime.db.DatasourceManagerImpl.getConnection(DatasourceManagerImpl.java:79) at lucee.runtime.tag.Query.executeDatasoure(Query.java:1120) at lucee.runtime.tag.Query._doEndTag(Query.java:702) at lucee.runtime.tag.Query.doEndTag(Query.java:567) at test.ldev2652.test_cfm$cf.call(/test/LDEV2652/test.cfm:3) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1058) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:950) at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:221) at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44)

But still, it throws the NPE on lucee latest version 5.4.0.40-SNAPSHOT.

Pothys - MitrahSoft 24 January 2020 at 15:26

I've checked this ticket & confirmed the issue happened on lucee as you said. Lucee throws a "Nullpointer exception" when we didn't use a correct connection string.

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Created 24 January 2020 at 00:21
Updated 15 November 2023 at 22:25

Flag notifications