Apache Lucene open-source search software
SOLR-10190: Fix NPE in CloudSolrClient when reading stale alias
Tomas Fernandez Lobbe39887b86297e
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 0302615bb33..2b0044c3f6e 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -275,6 +275,8 @@ Bug Fixes* SOLR-10083: Fix instanceof check in ConstDoubleSource.equals (Pushkar Raste via Christine Poerschke)+* SOLR-10190: Fix NPE in CloudSolrClient when reading stale alias (Janosch Woschitz via Tomás Fernández Löbbe)+================== 6.4.1 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.javaindex d0263c818ea..3147d4e50ef 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java@@ -1075,6 +1075,9 @@ public class CloudSolrClient extends SolrClient {for (String requestedCollection : requestedCollectionNames) {// track the version of state we're using on the client side using the _stateVer_ paramDocCollection coll = getDocCollection(requestedCollection, null);+ if (coll == null) {+ throw new SolrException(ErrorCode.BAD_REQUEST, "Collection not found: " + requestedCollection);+ }int collVer = coll.getZNodeVersion();if (coll.getStateFormat()>1) {if(requestedCollections == null) requestedCollections = new ArrayList<>(requestedCollectionNames.size());diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.javaindex 1698075dfb1..cff5c239ef5 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java@@ -146,6 +146,31 @@ public class CloudSolrClientTest extends SolrCloudTestCase {}+ @Test+ public void testHandlingOfStaleAlias() throws Exception {+ try (CloudSolrClient client = getCloudSolrClient(cluster.getZkServer().getZkAddress())) {+ client.setDefaultCollection("misconfigured-alias");++ CollectionAdminRequest.createCollection("nemesis", "conf", 2, 1).process(client);+ CollectionAdminRequest.createAlias("misconfigured-alias", "nemesis").process(client);+ CollectionAdminRequest.deleteCollection("nemesis").process(client);++ List<SolrInputDocument> docs = new ArrayList<>();++ SolrInputDocument doc = new SolrInputDocument();+ doc.addField(id, Integer.toString(1));+ docs.add(doc);++ try {+ client.add(docs);+ fail("Alias points to non-existing collection, add should fail");+ } catch (SolrException e) {+ assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, e.code());+ assertTrue("Unexpected error exception", e.getMessage().contains("Collection not found"));+ }+ }+ }+@Testpublic void testRouting() throws Exception {