When attempting to connect to a DataSource that specifies a database that doesn't exist, Tomcat 8.5.46 throws an informative SQLException; for example: java.sql.SQLException: Cannot create PoolableConnectionFactory (FATAL: database "labkey19.3" does not exist)

In the same situation, Tomcat 7.0.96 throws a NullPointerException with no useful information.

I expect an exception, but the 8.5.46/DBCP2 behavior is obviously preferable, since it gives administrators a better understanding of what's gone wrong. Seems like a DBCP 1.x bug (not a Tomcat bug) and I wouldn't consider it a high priority to fix (our product recovers just fine in either case and we recommend Tomcat 9.0.x these days), but the discrepancy seemed worth mentioning here.

Full stack traces below. Our code is simply:

    try (Connection conn = dataSource.getConnection())
    {
    ...
    }

Thanks,
Adam


Tomcat 7.0.96

java.lang.NullPointerException
    at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.destroyObject(PoolableConnectionFactory.java:643)     at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1738)     at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1721)     at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1486)     at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1103)
    at org.labkey.api.data.DbScope.<init>(DbScope.java:337)
    at org.labkey.api.data.DbScope.addScope(DbScope.java:1275)
    at org.labkey.api.data.DbScope.initializeScopes(DbScope.java:1243)
    at org.labkey.api.module.ModuleLoader.initializeDataSources(ModuleLoader.java:1004)
    at org.labkey.api.module.ModuleLoader.doInit(ModuleLoader.java:352)
    at org.labkey.api.module.ModuleLoader.init(ModuleLoader.java:249)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)     at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)     at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)     at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:5037)     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5739)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1018)     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:994)     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:662)     at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:712)     at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:2002)     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)     at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:830)

Tomcat 8.5.46

java.sql.SQLException: Cannot create PoolableConnectionFactory (FATAL: database "labkey19.3" does not exist)     at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:669)     at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:544)     at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:753)
    at org.labkey.api.data.DbScope.<init>(DbScope.java:337)
    at org.labkey.api.data.DbScope.addScope(DbScope.java:1275)
    at org.labkey.api.data.DbScope.initializeScopes(DbScope.java:1243)
    at org.labkey.api.module.ModuleLoader.initializeDataSources(ModuleLoader.java:1004)
    at org.labkey.api.module.ModuleLoader.doInit(ModuleLoader.java:352)
    at org.labkey.api.module.ModuleLoader.init(ModuleLoader.java:249)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:283)     at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:264)     at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)     at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4546)     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5191)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)     at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:614)     at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1823)     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)     at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: org.postgresql.util.PSQLException: FATAL: database "labkey19.3" does not exist     at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)     at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2559)     at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:133)     at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:250)     at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
    at org.postgresql.Driver.makeConnection(Driver.java:454)
    at org.postgresql.Driver.connect(Driver.java:256)
    at org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:55)     at org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:355)     at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:115)     at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:665)
    ... 25 more


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to