This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 75421c12a07 minor: CloudSolrClient.close: don't throw (#3878)
75421c12a07 is described below
commit 75421c12a078001881577438c66de77b8c52e27d
Author: David Smiley <[email protected]>
AuthorDate: Tue Nov 25 23:12:06 2025 -0500
minor: CloudSolrClient.close: don't throw (#3878)
CloudSolrClient.close needn't declare that it throws anything; it should
generally throw nothing if there's an unexpected problem.
---
.../client/solrj/impl/CloudHttp2SolrClient.java | 29 ++++++++--------------
.../solr/client/solrj/impl/CloudSolrClient.java | 2 +-
.../solrj/impl/CloudHttp2SolrClientTest.java | 26 +++----------------
.../client/solrj/impl/CloudSolrClientTest.java | 9 ++-----
.../client/solrj/apache/CloudLegacySolrClient.java | 6 ++---
5 files changed, 20 insertions(+), 52 deletions(-)
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
index 0bb4d3eb67a..4fc82b630d3 100644
---
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
+++
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
@@ -17,7 +17,6 @@
package org.apache.solr.client.solrj.impl;
-import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
@@ -29,6 +28,7 @@ import
org.apache.solr.client.solrj.impl.SolrZkClientTimeout.SolrZkClientTimeout
import org.apache.solr.client.solrj.request.RequestWriter;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -128,8 +128,8 @@ public class CloudHttp2SolrClient extends CloudSolrClient {
}
return stateProvider;
} catch (Exception e) {
- closeMyClientIfNeeded();
- throw (e);
+ close();
+ throw e;
}
}
@@ -138,7 +138,7 @@ public class CloudHttp2SolrClient extends CloudSolrClient {
try {
return new Http2ClusterStateProvider<>(solrUrls, httpClient);
} catch (Exception e) {
- closeMyClientIfNeeded();
+ close(); // doesn't throw
throw new RuntimeException(
"Couldn't initialize a HttpClusterStateProvider (is/are the "
+ "Solr server(s), "
@@ -148,23 +148,14 @@ public class CloudHttp2SolrClient extends CloudSolrClient
{
}
}
- private void closeMyClientIfNeeded() {
- try {
- if (clientIsInternal && myClient != null) {
- myClient.close();
- }
- } catch (Exception e) {
- throw new RuntimeException("Exception on closing myClient", e);
- }
- }
-
@Override
- public void close() throws IOException {
- stateProvider.close();
- lbClient.close();
-
- closeMyClientIfNeeded();
+ public void close() {
+ IOUtils.closeQuietly(stateProvider);
+ IOUtils.closeQuietly(lbClient);
+ if (clientIsInternal) {
+ IOUtils.closeQuietly(myClient);
+ }
super.close();
}
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index 4922edc8aaa..cecbc4fcd23 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -227,7 +227,7 @@ public abstract class CloudSolrClient extends SolrClient {
}
@Override
- public void close() throws IOException {
+ public void close() {
if (this.threadPool != null && !ExecutorUtil.isShutdown(this.threadPool)) {
ExecutorUtil.shutdownAndAwaitTermination(this.threadPool);
this.threadPool = null;
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
index 060d01a6414..cf490ce042e 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
@@ -68,6 +68,7 @@ import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.params.UpdateParams;
+import org.apache.solr.common.util.IOUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.URLUtil;
@@ -153,28 +154,9 @@ public class CloudHttp2SolrClientTest extends
SolrCloudTestCase {
@AfterClass
public static void tearDownAfterClass() throws Exception {
-
- if (httpJettyBasedCloudSolrClient != null) {
- try {
- httpJettyBasedCloudSolrClient.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- if (httpJdkBasedCloudSolrClient != null) {
- try {
- httpJdkBasedCloudSolrClient.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- if (zkBasedCloudSolrClient != null) {
- try {
- zkBasedCloudSolrClient.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+ IOUtils.closeQuietly(httpJettyBasedCloudSolrClient);
+ IOUtils.closeQuietly(httpJdkBasedCloudSolrClient);
+ IOUtils.closeQuietly(zkBasedCloudSolrClient);
shutdownCluster();
httpJettyBasedCloudSolrClient = null;
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
index 7f45e692827..5a7ae3963b0 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
@@ -72,6 +72,7 @@ import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.params.UpdateParams;
+import org.apache.solr.common.util.IOUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.URLUtil;
@@ -121,13 +122,7 @@ public class CloudSolrClientTest extends SolrCloudTestCase
{
@AfterClass
public static void tearDownAfterClass() throws Exception {
- if (httpBasedCloudSolrClient != null) {
- try {
- httpBasedCloudSolrClient.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+ IOUtils.closeQuietly(httpBasedCloudSolrClient);
httpBasedCloudSolrClient = null;
shutdownCluster();
diff --git
a/solr/test-framework/src/java/org/apache/solr/client/solrj/apache/CloudLegacySolrClient.java
b/solr/test-framework/src/java/org/apache/solr/client/solrj/apache/CloudLegacySolrClient.java
index 51ec0cca26a..1be96a11d46 100644
---
a/solr/test-framework/src/java/org/apache/solr/client/solrj/apache/CloudLegacySolrClient.java
+++
b/solr/test-framework/src/java/org/apache/solr/client/solrj/apache/CloudLegacySolrClient.java
@@ -16,7 +16,6 @@
*/
package org.apache.solr.client.solrj.apache;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -38,6 +37,7 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocRouter;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.IOUtils;
import org.apache.solr.common.util.NamedList;
/**
@@ -116,8 +116,8 @@ public class CloudLegacySolrClient extends CloudSolrClient {
}
@Override
- public void close() throws IOException {
- stateProvider.close();
+ public void close() {
+ IOUtils.closeQuietly(stateProvider);
if (shutdownLBHttpSolrServer) {
lbClient.close();