puneeetsharma commented on code in PR #3436:
URL: https://github.com/apache/solr/pull/3436#discussion_r2240410507
##########
solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java:
##########
@@ -545,8 +545,11 @@ protected void doAddDistinct(SolrInputDocument toDoc,
SolrInputField sif, Object
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;
Review Comment:
Previously, if existingField was null, we were assigning original to a new
ArrayList<>, which was fine. However, if existingField.getValues() returned
null, then original would also be assigned null, leading to a
NullPointerException when calling original.size().
In the new code, whether existingField is null or existingField.getValues()
returns null, original is initially set to null. We then explicitly check for
null and assign it to a new ArrayList<> if needed. This ensures that original
is never null when calling size(), thus avoiding the NPE.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]