diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 0826ce75f10..486726c806d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -103,6 +103,9 @@ New Features
This is intended to eventually replace the Suggester support through the
SpellCheckComponent. (Areek Zillur, Varun Thacker via shalin)
+* SOLR-5494: CoreContainer#remove throws NPE rather than returning null when
+ a SolrCore does not exist in core discovery mode. (Mark Miller)
+
Bug Fixes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/core/CorePropertiesLocator.java b/solr/core/src/java/org/apache/solr/core/CorePropertiesLocator.java
index 087a37b3f6f..a4fa2ae0d1b 100644
--- a/solr/core/src/java/org/apache/solr/core/CorePropertiesLocator.java
+++ b/solr/core/src/java/org/apache/solr/core/CorePropertiesLocator.java
@@ -91,7 +91,11 @@ public class CorePropertiesLocator implements CoresLocator {
@Override
public void delete(CoreContainer cc, CoreDescriptor... coreDescriptors) {
+ if (coreDescriptors == null) {
+ return;
+ }
for (CoreDescriptor cd : coreDescriptors) {
+ if (cd == null) continue;
File instanceDir = new File(cd.getInstanceDir());
File propertiesFile = new File(instanceDir, PROPERTIES_FILENAME);
propertiesFile.renameTo(new File(instanceDir, PROPERTIES_FILENAME + ".unloaded"));
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 0c0aa3b95fa..5679943c24a 100644
--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
@@ -149,7 +149,10 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
//create solrHome
File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName()
+ "_noCores");
- SetUpHome(solrHomeDirectory, EMPTY_SOLR_XML);
+
+ boolean oldSolrXml = random().nextBoolean();
+
+ SetUpHome(solrHomeDirectory, oldSolrXml ? EMPTY_SOLR_XML : EMPTY_SOLR_XML2);
CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
cores.load();
try {
@@ -166,14 +169,19 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
assertEquals("There core registered", 1, cores.getCores().size());
-
- assertXmlFile(new File(solrHomeDirectory, "solr.xml"),
- "/solr/cores[@transientCacheSize='32']");
+ if (oldSolrXml) {
+ assertXmlFile(new File(solrHomeDirectory, "solr.xml"),
+ "/solr/cores[@transientCacheSize='32']");
+ }
newCore.close();
cores.remove("core1");
//assert cero cores
assertEquals("There should not be cores", 0, cores.getCores().size());
+
+ // try and remove a core that does not exist
+ SolrCore ret = cores.remove("non_existent_core");
+ assertNull(ret);
} finally {
cores.shutdown();
FileUtils.deleteDirectory(solrHomeDirectory);
@@ -275,4 +283,8 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
" \n" +
" \n" +
"";
+
+ private static final String EMPTY_SOLR_XML2 ="\n" +
+ "\n" +
+ "";
}