Description:
The AbandonedConnectionCleanupThread calls Thread.setContextClassLoader in a static block
which may throw a SecurityException if a SecurityManager is in place.
This can prevent the driver class from instantiating in tomcat with the
-security flag enabled.
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "setContextClassLoader")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.Thread.setContextClassLoader(Thread.java:1474)
at com.mysql.jdbc.AbandonedConnectionCleanupThread$1.newThread(AbandonedConnectionCleanupThread.java:50)
at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:619)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:932)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1367)
How to repeat:
Run
Class.forName("com.mysql.jdbc.Driver") from a tomcat application when
tomcat is run with the -security flag.
Same in test class with a security.policy file that dis-allows setContextClassLoader
Suggested fix:
Trap the exception
Running with the thread classloader is better than not loading at all.