This is an automated email from the ASF dual-hosted git repository. dsmiley pushed a commit to branch branch_9x in repository https://gitbox.apache.org/repos/asf/solr.git
commit e3b75ae8645724bbebe23174f578aea39ec6f8e5 Author: David Smiley <[email protected]> AuthorDate: Wed Sep 10 00:36:04 2025 -0400 minor: HttpSolrClient NPE avoidance (#3629) This PR fixes a potential NPE in HttpSolrClient by deferring the call to entity.getContent() until after null checks are performed and providing a safe fallback when the entity is null. * Moves entity.getContent() call after null checks to avoid NPE * Adds null-safe fallback using empty ByteArrayInputStream when entity is null * Removes unnecessary early declaration of respBody variable (cherry picked from commit 6557ad3c60efe0852c8380bc7601fc808019fae3) --- .../src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java index d73356ccc68..a277ed16513 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java @@ -18,6 +18,7 @@ package org.apache.solr.client.solrj.impl; import static org.apache.solr.common.util.Utils.getObjectByPath; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -566,7 +567,6 @@ public class HttpSolrClient extends BaseHttpSolrClient { method.setConfig(requestConfigBuilder.build()); HttpEntity entity = null; - InputStream respBody = null; boolean shouldClose = true; try { // Execute the method. @@ -584,7 +584,6 @@ public class HttpSolrClient extends BaseHttpSolrClient { // Read the contents entity = response.getEntity(); - respBody = entity.getContent(); String mimeType = null; Charset charset = null; String charsetName = null; @@ -624,6 +623,9 @@ public class HttpSolrClient extends BaseHttpSolrClient { null); } } + + InputStream respBody = + (entity == null ? new ByteArrayInputStream(new byte[0]) : entity.getContent()); if (processor == null || processor instanceof InputStreamResponseParser) { // no processor specified, return raw stream final var rsp =
