You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "Jalaz Kumar (Jira)" <ji...@apache.org> on 2026/05/14 20:29:00 UTC

[jira] [Comment Edited] (SOLR-18239) `ObjectSizeEstimator.primitiveEstimate()` calls `obj.getClass()` without checking if `obj` is null

    [ https://issues.apache.org/jira/browse/SOLR-18239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18080961#comment-18080961 ] 

Jalaz Kumar edited comment on SOLR-18239 at 5/14/26 8:28 PM:
-------------------------------------------------------------

[~aarondr] Can I take this up & raise the PR?

[update] checked GitHub, couldn't find any PR raised yet. so, I have raised one. Can you help review it? 


was (Author: JIRAUSER311120):
[~aarondr] Can I take this up & raise this PR?

> `ObjectSizeEstimator.primitiveEstimate()` calls `obj.getClass()` without checking if `obj` is null
> --------------------------------------------------------------------------------------------------
>
>                 Key: SOLR-18239
>                 URL: https://issues.apache.org/jira/browse/SOLR-18239
>             Project: Solr
>          Issue Type: Bug
>          Components: CrossDC
>    Affects Versions: 9.10.1
>         Environment: Using the CrossDC manager, fields that were not a problem without the CrossDC manager enabled are causing this failure.
>            Reporter: Aaron Dockter
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> h2. Issue
> Apache Solr cross-DC replication was failing with {{NullPointerException}} in the {{MirroringUpdateProcessor}} when indexing documents containing fields with null values. The error occurred in {{ObjectSizeEstimator.primitiveEstimate()}} which called {{obj.getClass()}} without checking if {{obj}} was null.
> h2. Root Cause
> {{MirroringUpdateProcessor.ObjectSizeEstimator.primitiveEstimate(Object obj, long def)}} did not check for null before calling {{{}obj.getClass(){}}}. When a {{SolrInputDocument}} contained a field with a null value, the size estimator would crash during cross-DC mirroring.
> h2. Resolution Fix
> Added a null guard at the start of the {{primitiveEstimate}} method:
>  
> {{private static long primitiveEstimate(Object obj, long def) {    if (obj == null) return def;
>     Class<?> clazz = obj.getClass();
>     ...
> }}}
> This ensures that when a field value is null, the method returns the default size estimate instead of attempting to introspect the class type.
> h2. Tests to Add
> Added a regression test in {{MirroringUpdateProcessorTest.java}} to verify the fix:
>  
> {{@Testpublic void testObjectSizeEstimatorWithNullFieldValue() {    SolrInputDocument doc = new SolrInputDocument();
>     doc.addField("id", "test");
>     doc.addField("nullField", null);    long size = MirroringUpdateProcessor.ObjectSizeEstimator.estimate(doc);
>     assertTrue("size should be non-negative", size >= 0);
> }}}
> This test creates a {{SolrInputDocument}} with a field explicitly set to {{null}} and verifies that {{ObjectSizeEstimator.estimate()}} completes successfully without throwing a {{{}NullPointerException{}}}.
> h2. Files Requiring Changes (Solr cross-dc module)
>  * {{solr/solr/modules/cross-dc/src/java/org/apache/solr/crossdc/update/processor/MirroringUpdateProcessor.java}} — Added null guard in {{primitiveEstimate()}}
>  * {{solr/solr/modules/cross-dc/src/test/org/apache/solr/crossdc/update/processor/MirroringUpdateProcessorTest.java}} — Added regression test {{testObjectSizeEstimatorWithNullFieldValue()}}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org