diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 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.java index 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_ param DocCollection 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.java index 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 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")); + } + } + } + @Test public void testRouting() throws Exception {