Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

minor: HttpSolrClient NPE avoidance (#3629)

David Smiley6557ad3c60ef
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 3f6e5a28c85..b5de3894268 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;
@@ -550,7 +551,6 @@ public class HttpSolrClient extends BaseHttpSolrClient {
method.setConfig(requestConfigBuilder.build());
HttpEntity entity = null;
- InputStream respBody = null;
boolean shouldClose = true;
try {
// Execute the method.
@@ -568,7 +568,6 @@ public class HttpSolrClient extends BaseHttpSolrClient {
// Read the contents
entity = response.getEntity();
- respBody = entity.getContent();
String mimeType = null;
Charset charset = null;
String charsetName = null;
@@ -608,6 +607,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 =