Skip to content

Commit

Permalink
Fixing NPE in MemoryLeakUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
dkayiwa committed Feb 14, 2014
1 parent 8d24054 commit b527b96
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/src/main/java/org/openmrs/util/MemoryLeakUtil.java
Expand Up @@ -69,11 +69,23 @@ public static void shutdownMysqlCancellationTimer() {
public static void shutdownKeepAliveTimer() {
try {
final Field kac = HttpClient.class.getDeclaredField("kac");
if (kac == null) {
return;
}

kac.setAccessible(true);
final Field keepAliveTimer = KeepAliveCache.class.getDeclaredField("keepAliveTimer");
if (keepAliveTimer == null) {
return;
}

keepAliveTimer.setAccessible(true);

final Thread thread = (Thread) keepAliveTimer.get(kac.get(null));
if (thread == null) {
return;
}

if (thread.getContextClassLoader() == OpenmrsClassLoader.getInstance()) {
//Set to system class loader such that we can be garbage collected.
thread.setContextClassLoader(ClassLoader.getSystemClassLoader());
Expand Down

0 comments on commit b527b96

Please sign in to comment.