Skip to content

Apache Lucene open-source search software

SOLR-14162 TestInjection can leak Timer objects (#1137)

Mikeeaa3dbe44087
diff --git a/solr/core/src/java/org/apache/solr/util/TestInjection.java b/solr/core/src/java/org/apache/solr/util/TestInjection.java
index ec120d617fe..eb04f4ebbb3 100644
--- a/solr/core/src/java/org/apache/solr/util/TestInjection.java
+++ b/solr/core/src/java/org/apache/solr/util/TestInjection.java
@@ -257,8 +257,9 @@ public class TestInjection {
if (rand.nextBoolean()) {
throw new TestShutdownFailError("Test exception for non graceful close");
} else {
-
+ final Timer timer = new Timer();
final Thread cthread = Thread.currentThread();
+
TimerTask task = new TimerTask() {
@Override
public void run() {
@@ -275,11 +276,10 @@ public class TestInjection {
}
cthread.interrupt();
- timers.remove(this);
- cancel();
+ timers.remove(timer);
}
};
- Timer timer = new Timer();
+
timers.add(timer);
timer.schedule(task, rand.nextInt(500));
}