db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1620385 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/timer/SingletonTimerFactory.java
Date Mon, 25 Aug 2014 17:33:49 GMT
Author: dag
Date: Mon Aug 25 17:33:49 2014
New Revision: 1620385

URL: http://svn.apache.org/r1620385
DERBY-6619 After silently swallowing SecurityExceptions, Derby can leak class loaders

Patch derby-6619-2-refinement which implements the following
refinements to the test to avoid changing the context class loader in
SingletonTimerFactory (suggested by Knut):

The orginal test tested against the system class loader. This new patch will:

1) Check if the context class loader is the same as the loader of the
SingletonTimerFactory class (that is, the class loader from which
Derby classes are loaded). Even if this isn't the same as the system
class loader, it would be safe to skip the workaround for DERBY-3745,
since the class loader for the Derby classes would not be eligible for
garbage collection until the engine is shut down anyway. This would
prevent some more false positives from being reported in
derby.log. I'd assume this is a kind of false positive that could
easily occur in an application server environment where the Derby
classes are not found on the system class loader.

2) Check against Thread.class.getClassLoader() instead of
ClassLoader.getSystemClassLoader(). Normally, those two checks would
be identical. If however the setup is such that they aren't identical,
we'd still know that the class loader actually used for system classes
such as the Thread class would have to stay in memory for as long as
the timer thread is alive, regardless of the context class loader of
the thread, so the workaround for DERBY-3745 can be skipped if it's
the same as the context class loader. The check will be a bit more
specific this way.


Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/timer/SingletonTimerFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/timer/SingletonTimerFactory.java?rev=1620385&r1=1620384&r2=1620385&view=diff
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/timer/SingletonTimerFactory.java
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/timer/SingletonTimerFactory.java
Mon Aug 25 17:33:49 2014
@@ -175,13 +175,14 @@ public class SingletonTimerFactory
                 public ClassLoader run() {
                     ClassLoader cl =
-                    if (cl == ClassLoader.getSystemClassLoader()) {
-                        // If the context class loader is the same as the
-                        // system class loader, we are not worried that the
-                        // timer thread will lead a class loader. (The
-                        // system class loader will stay in memory for the
+                    if (cl == getClass().getClassLoader() ||
+                        cl == Thread.class.getClassLoader()) {
+                        // If the context class loader is the same as any of
+                        // these class loaders, we are not worried that the
+                        // timer thread will lead a class loader. These
+                        // class loaders will stay in memory for the
                         // lifetime of the JVM anyway, so it's not a problem
-                        // that the timer thread keeps a reference to it.)
+                        // that the timer thread keeps a reference to it.
                         // Return null to signal that the context class loader
                         // doesn't need to be changed.
                         return null;

View raw message