This is an automated email from the ASF dual-hosted git repository.

epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new a1ebd0433c7 SOLR-17721 - null pointer fix in the doAddDistinct method 
(#3436)
a1ebd0433c7 is described below

commit a1ebd0433c71a5527429d6671c901452f0e8bdb5
Author: Puneet Sharma <[email protected]>
AuthorDate: Wed Jul 30 01:39:59 2025 +0530

    SOLR-17721 - null pointer fix in the doAddDistinct method (#3436)
    
    
    
    Co-authored-by: Puneet Sharma <[email protected]>
    Co-authored-by: Eric Pugh <[email protected]>
---
 solr/CHANGES.txt                                   |  2 ++
 .../processor/AtomicUpdateDocumentMerger.java      |  7 +++++--
 .../solr/update/processor/AtomicUpdatesTest.java   | 23 ++++++++++++++++++++++
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index ab044e2f409..04099f55806 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -218,6 +218,8 @@ Bug Fixes
 
 * SOLR-17824: RecoveryStrategy.pingLeader could NPE when there's no shard 
leader (David Smiley)
 
+* SOLR-17721: NPE can occur when doing Atomic Update using Add Distinct on 
documents with a null field value. (puneetSharma via Eric Pugh)
+
 Dependency Upgrades
 ---------------------
 (No changes)
diff --git 
a/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
 
b/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
index dbfd33959bd..01fab007eb3 100644
--- 
a/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
+++ 
b/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
@@ -545,8 +545,11 @@ public class AtomicUpdateDocumentMerger {
     final String name = sif.getName();
     SolrInputField existingField = toDoc.get(name);
 
-    Collection<Object> original =
-        existingField != null ? existingField.getValues() : new ArrayList<>();
+    Collection<Object> original = existingField != null ? 
existingField.getValues() : null;
+
+    if (original == null) {
+      original = new ArrayList<>();
+    }
 
     int initialSize = original.size();
     if (fieldVal instanceof Collection) {
diff --git 
a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java 
b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java
index 5194e1ea1ba..96813d95344 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java
@@ -1704,4 +1704,27 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
         "*[count(//result/doc[1]/arr[@name='intRemove']/int)=1]",
         "//result/doc[1]/arr[@name='intRemove']/int[1][.=333]");
   }
+
+  @Test
+  public void testAddDistinctToNullField() {
+    // Test that add-distinct works correctly when the field value is null
+    SolrInputDocument doc = new SolrInputDocument();
+    doc.setField("id", 9999);
+    doc.setField("cat", null); // Set field to null
+    assertU(adoc(doc));
+    assertU(commit());
+
+    // Now try to add-distinct to the null field
+    doc = new SolrInputDocument();
+    doc.setField("id", 9999);
+    doc.setField("cat", Map.of("add-distinct", "new_value"));
+    assertU(adoc(doc));
+    assertU(commit());
+
+    // Verify the value was added
+    assertQ(
+        req("q", "id:9999", "indent", "true"),
+        "//result[@numFound = '1']",
+        "//doc/arr[@name='cat']/str[.='new_value']");
+  }
 }

Reply via email to