>> Doesn't seem to affect anything

Actually it does, because due to the exception some memory is not de-allocated properly, which might cause a memory leak (it does in our case).

We have investigated a bit on this problem and we have found that (on Tomcat 6.0) there is a race condition. The resourceDestroyer thread (inside the close method of BasicResourcePool) is executed asynchronously and takes some time to complete, so if you start it immediately before undeploying the application it is possible that the Tomcat WebappClassLoader starts clearing all the references to the loaded classes (including C3P0 ones) WHILE the resourceDestroyer thread is still running. As a consequence, the logger reference is found null by resourceDestroyer and a NullPointerException is raised.

As a proof of what I said, we have implemented a ContextListener which is called by Tomcat every time an application is stopped or undeployed, and we have added a sleep right after calling the DataSources.destroy() in C3P0. This way we give time to the resourceDestroyer to complete his job BEFORE the Tomcat WebappClassLoader nullifies references inside C3P0.

We have written a simple test performing a deploy/stop/undeploy cycle of a C3P0 application. With a zero-seconds sleep, our test raises the null-pointer exception once out of ten cycles. With a 20 secs sleep, the test has completed 2500 cycles with no null-pointer exceptions at all (we had to stop it manually).

By the way, with a zero-seconds sleep, we also had another problem during the stop/undeploy of C3P0 applications: a java.util.ConcurrentModificationException was raised by Tomcat WebappClassLoader when it tried to clone the references map in the method clearReferences(). This problem also disappears when we set a 20 secs sleep, so we believe that it is caused by the same race condition raising the NullPointerException.

We suggets to modify the close method of BasicResourcePool adding a join to the resourceDestroyer thread. We would do it ourselves (and release the patch to the community) if only we had a building ANT script that works. The one we have fails to build C3P0 with several compilation errors...