Apache Solr open-source search software
HttpJdkSolrClient: Close the underlying http client, if it is supported (java 21+) (#2362)
James Dyer3cf0d6908f3a
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.javaindex 63d1d3ca207..35e56ae2a55 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java@@ -410,14 +410,21 @@ public class HttpJdkSolrClient extends HttpSolrClientBase {@Overridepublic void close() throws IOException {+ // If used with Java 21++ if (httpClient instanceof AutoCloseable) {+ try {+ ((AutoCloseable) httpClient).close();+ } catch (Exception e) {+ log.warn("Could not close the http client.", e);+ }+ }+ httpClient = null;+if (shutdownExecutor) {ExecutorUtil.shutdownAndAwaitTermination(executor);}executor = null;- // TODO: Java 21 adds close/autoclosable to HttpClient. We should use it.- httpClient = null;-assert ObjectReleaseTracker.release(this);}