NPE in DBCP when attempting to connect to a database that doesn't exist

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

NPE in DBCP when attempting to connect to a database that doesn't exist

Adam Rauch-2
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: NPE in DBCP when attempting to connect to a database that doesn't exist

Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Adam,

On 10/9/19 20:59, Adam Rauch wrote:

> 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

Sounds like a bona-fide bug. Can you please file this in Bugzilla?

- -chris

>
> Tomcat 7.0.96
>
> java.lang.NullPointerException at
> org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.destroyObject(Po
olableConnectionFactory.java:643)
>
>  at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(
BasicDataSource.java:1738)
>
>  at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFa
ctory(BasicDataSource.java:1721)
>
>  at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicData
Source.java:1486)
>
>  at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSou
rce.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(Applicatio
nFilterConfig.java:285)
>
>  at
> org.apache.catalina.core.ApplicationFilterConfig.getFilter(Application
FilterConfig.java:266)
>
>  at
> org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFil
terConfig.java:108)
>
>  at
> org.apache.catalina.core.StandardContext.filterStart(StandardContext.j
ava: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.jav
a:712)
>
>  at
> org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig
.java:2002)
>
>  at
> java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executor
s.java:515)
>
>  at
> java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.jav
a:264)
>
>  at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
> at
> java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPool
Executor.java:1128)
>
>  at
> java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoo
lExecutor.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.createPoolableConnectionF
actory(BasicDataSource.java:669)
>
>  at
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDat
aSource.java:544)
>
>  at
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSo
urce.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(Applicatio
nFilterConfig.java:283)
>
>  at
> org.apache.catalina.core.ApplicationFilterConfig.getFilter(Application
FilterConfig.java:264)
>
>  at
> org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFil
terConfig.java:108)
>
>  at
> org.apache.catalina.core.StandardContext.filterStart(StandardContext.j
ava: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.jav
a:614)
>
>  at
> org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig
.java:1823)
>
>  at
> java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executor
s.java:515)
>
>  at
> java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.jav
a:264)
>
>  at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
> at
> java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPool
Executor.java:1128)
>
>  at
> java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoo
lExecutor.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(QueryExe
cutorImpl.java:2440)
>
>  at
> org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExec
utorImpl.java:2559)
>
>  at
> org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java
:133)
>
>
at
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(Connec
tionFactoryImpl.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(Pool
ableConnectionFactory.java:355)
>
>  at
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory
(BasicDataSource.java:115)
>
>  at
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionF
actory(BasicDataSource.java:665)
>
>  ... 25 more
>
>
> ---------------------------------------------------------------------
>
>
To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl2fafgACgkQHPApP6U8
pFis8RAArxT8+RLqJB77GncSWANuesSUkC1Pa9T7bIxAAiGyxhn4nmRh6zHRkDOh
B58hbQ5DtvQhuFXBsWD26c3Duj+u3WQA5F8GuaD8q43KV7bIWevzJFBblP0zr+Ay
UDhChTazpx3r22/VYwJnSY/Ebele4/yrEVnRbw79ufvWVawjTNv3rs6jljpEWoBY
BstgsDvT5vEUpQanTkpV9tsW0f5PLEKDduUxVY0r9yEjTaTH40UvzQlb8w1Ql9tO
+iEWt0lRmasdf/aTUZuTz/+TOhLS2mT5KAN85HNM/wVsq/V/vx/EaJ6v5XKOVh5A
bRUQhBr1mFs3tt+CckjhCofgNAiTiAHeUkVk0awWAv0kYKVl/uJidnRuM1hPCOE4
N/4v8ZRp2ghg/Bjq+QupFwf0q29cXVIsZuR7+BB5/px7XEyEJ4VwcvbSgB5Q9DOI
w3lqhmCBwjxbKtfCTbQ775BY36s2azuW+N0xBojasrrS4BKAnkoahGhYoRGs1+0o
knyLTdRYHCaI738NJ23e52T8xVruQ/MgJ2swvg2VnZnCC8SxNXNg9pQ7/LKHR26f
m0an42BbTBIjm2evHgqi+IrnVGaOdfzFvRbmye7BZGL9ogcPSkeMMUJCGHpQi6Ma
28GlQ91mpuJPw4sDEIKuipKmlPSH6GHZllqcYmKLOXwLQpJF9Iw=
=eaTj
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]