Skip to content

Apache Lucene open-source search software

SOLR-13074: clean up static variables properly, avoiding NPEs.

Dawid Weiss71f024ac8f1b
diff --git a/solr/core/src/test/org/apache/solr/cloud/MoveReplicaHDFSTest.java b/solr/core/src/test/org/apache/solr/cloud/MoveReplicaHDFSTest.java
index bb6a2a8457c..e05033c9155 100644
--- a/solr/core/src/test/org/apache/solr/cloud/MoveReplicaHDFSTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/MoveReplicaHDFSTest.java
@@ -16,11 +16,14 @@
*/
package org.apache.solr.cloud;
+import java.io.IOException;
+
import com.carrotsearch.randomizedtesting.ThreadFilter;
import com.carrotsearch.randomizedtesting.annotations.Nightly;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
import org.apache.lucene.util.TimeUnits;
import org.apache.solr.cloud.hdfs.HdfsTestUtil;
@@ -57,9 +60,27 @@ public class MoveReplicaHDFSTest extends MoveReplicaTest {
@AfterClass
public static void teardownClass() throws Exception {
- cluster.shutdown(); // need to close before the MiniDFSCluster
- HdfsTestUtil.teardownClass(dfsCluster);
- dfsCluster = null;
+ try {
+ IOUtils.close(
+ () -> {
+ try {
+ if (cluster != null) cluster.shutdown();
+ } catch (Exception e) {
+ throw new IOException("Could not shut down the cluster.", e);
+ }
+ },
+ () -> {
+ try {
+ if (dfsCluster != null) HdfsTestUtil.teardownClass(dfsCluster);
+ } catch (Exception e) {
+ throw new IOException("Could not shut down dfs cluster.", e);
+ }
+ }
+ );
+ } finally {
+ cluster = null;
+ dfsCluster = null;
+ }
}
@Test
@@ -89,15 +110,11 @@ public class MoveReplicaHDFSTest extends MoveReplicaTest {
}
public static class ForkJoinThreadsFilter implements ThreadFilter {
-
@Override
public boolean reject(Thread t) {
String name = t.getName();
- if (name.startsWith("ForkJoinPool.commonPool")) {
- return true;
- }
- return false;
+ return name.startsWith("ForkJoinPool.commonPool");
}
}
-
}
+