Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-7705: CoreAdminHandler Unload no longer handles null core name

Shalin Shekhar Mangar2c64848c78d0
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 83b1737d3e0..57c7580cb74 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -224,6 +224,9 @@ Bug Fixes
* SOLR-7172: addreplica API fails with incorrect error msg "cannot create collection"
(Erick Erickson)
+* SOLR-7705: CoreAdminHandler Unload no longer handles null core name and throws NPE
+ instead of a bad request error. (John Call, Edward Ribeiro via shalin)
+
Optimizations
----------------------
@@ -245,7 +248,6 @@ Optimizations
(yonik)
-
Other Changes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index 0cf3476a7b1..17ac7e5d2a8 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -820,14 +820,16 @@ public class CoreContainer {
*/
public void unload(String name, boolean deleteIndexDir, boolean deleteDataDir, boolean deleteInstanceDir) {
- // check for core-init errors first
- CoreLoadFailure loadFailure = coreInitFailures.remove(name);
- if (loadFailure != null) {
- // getting the index directory requires opening a DirectoryFactory with a SolrConfig, etc,
- // which we may not be able to do because of the init error. So we just go with what we
- // can glean from the CoreDescriptor - datadir and instancedir
- SolrCore.deleteUnloadedCore(loadFailure.cd, deleteDataDir, deleteInstanceDir);
- return;
+ if (name != null) {
+ // check for core-init errors first
+ CoreLoadFailure loadFailure = coreInitFailures.remove(name);
+ if (loadFailure != null) {
+ // getting the index directory requires opening a DirectoryFactory with a SolrConfig, etc,
+ // which we may not be able to do because of the init error. So we just go with what we
+ // can glean from the CoreDescriptor - datadir and instancedir
+ SolrCore.deleteUnloadedCore(loadFailure.cd, deleteDataDir, deleteInstanceDir);
+ return;
+ }
}
CoreDescriptor cd = solrCores.getCoreDescriptor(name);
diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
index ffaa955bd7b..e5aa76f4a86 100644
--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
@@ -178,6 +178,18 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
assertThat(e.getMessage(), containsString("Cannot unload non-existent core [non_existent_core]"));
}
+ // try and remove a null core
+ try {
+ cores.unload(null);
+ fail("Should have thrown an exception when unloading a null core");
+ }
+ catch (Exception e) {
+ if (!(e instanceof SolrException)) {
+ fail("Should not have thrown SolrException but got " + e);
+ }
+ assertThat(e.getMessage(), containsString("Cannot unload non-existent core [null]"));
+ }
+
} finally {
cores.shutdown();
}