From 521eb2f4af92252e10f905e5bd6d8a7b26f38b67 Mon Sep 17 00:00:00 2001 From: adityamparikh Date: Fri, 24 Apr 2026 14:14:31 -0400 Subject: [PATCH] fix: narrow catch clauses in fetchCacheMetrics/fetchHandlerMetrics Change catch from RuntimeException to SolrException in fetchCacheMetrics() and fetchHandlerMetrics(). This still catches Solr 10's RemoteSolrException (subclass of SolrException) for graceful degradation when /admin/mbeans is unavailable, but no longer swallows programming bugs like NPE or ClassCastException. Closes #4 Signed-off-by: Aditya Parikh Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: adityamparikh --- .../apache/solr/mcp/server/collection/CollectionService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java b/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java index 48ec56d3..917ce9ab 100644 --- a/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java +++ b/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java @@ -38,6 +38,7 @@ import org.apache.solr.client.solrj.response.LukeResponse; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.client.solrj.response.SolrPingResponse; +import org.apache.solr.common.SolrException; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.mcp.server.config.SolrConfigurationProperties; @@ -579,7 +580,7 @@ private CacheStats fetchCacheMetrics(String collection) { CacheStats stats = extractCacheStats(coreMetrics); return isCacheStatsEmpty(stats) ? null : stats; - } catch (SolrServerException | IOException | RuntimeException _) { + } catch (SolrServerException | IOException | SolrException e) { return null; } } @@ -693,7 +694,7 @@ private HandlerStats fetchHandlerMetrics(String collection) { HandlerStats stats = new HandlerStats(selectHandler, updateHandler); return isHandlerStatsEmpty(stats) ? null : stats; - } catch (SolrServerException | IOException | RuntimeException _) { + } catch (SolrServerException | IOException | SolrException e) { return null; } }