This is an automated email from the ASF dual-hosted git repository.

epugh pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_10x by this push:
     new adf9c505e49 SOLR-18066: Fix hideIgnoreStackTrace from the solr.xml 
(#4278)
adf9c505e49 is described below

commit adf9c505e494b40f55ef1170331c3fdbc3582b50
Author: Utsav <[email protected]>
AuthorDate: Wed Jun 3 23:57:37 2026 +0530

    SOLR-18066: Fix hideIgnoreStackTrace from the solr.xml (#4278)
    
    (cherry picked from commit c67e4e4677c48405d4c9b7af2e39477adc305d5a)
---
 .../SOLR-18066-enable-hideStackTrace.yml           |  7 ++
 .../solr/jersey/CatchAllExceptionMapper.java       | 15 ++++-
 .../solr/servlet/CatchAllExceptionMapperTest.java  | 75 ++++++++++++++++++++++
 3 files changed, 95 insertions(+), 2 deletions(-)

diff --git a/changelog/unreleased/SOLR-18066-enable-hideStackTrace.yml 
b/changelog/unreleased/SOLR-18066-enable-hideStackTrace.yml
new file mode 100644
index 00000000000..2b26c762613
--- /dev/null
+++ b/changelog/unreleased/SOLR-18066-enable-hideStackTrace.yml
@@ -0,0 +1,7 @@
+title: "V2 APIs now properly respect the hideStackTrace config setting"
+type: fixed
+authors:
+  - name: Utsav Parmar
+links:
+  - name: SOLR-18066
+    url: https://issues.apache.org/jira/browse/SOLR-18066
diff --git 
a/solr/core/src/java/org/apache/solr/jersey/CatchAllExceptionMapper.java 
b/solr/core/src/java/org/apache/solr/jersey/CatchAllExceptionMapper.java
index e80c922513e..506aa0670ac 100644
--- a/solr/core/src/java/org/apache/solr/jersey/CatchAllExceptionMapper.java
+++ b/solr/core/src/java/org/apache/solr/jersey/CatchAllExceptionMapper.java
@@ -18,6 +18,7 @@
 package org.apache.solr.jersey;
 
 import static org.apache.solr.common.SolrException.ErrorCode.getErrorCode;
+import static org.apache.solr.jersey.RequestContextKeys.CORE_CONTAINER;
 import static org.apache.solr.jersey.RequestContextKeys.HANDLER_METRICS;
 import static org.apache.solr.jersey.RequestContextKeys.SOLR_JERSEY_RESPONSE;
 import static org.apache.solr.jersey.RequestContextKeys.SOLR_QUERY_REQUEST;
@@ -33,6 +34,7 @@ import jakarta.ws.rs.ext.ExceptionMapper;
 import java.lang.invoke.MethodHandles;
 import org.apache.solr.client.api.model.SolrJerseyResponse;
 import org.apache.solr.common.SolrException;
+import org.apache.solr.core.CoreContainer;
 import org.apache.solr.handler.RequestHandlerBase;
 import org.apache.solr.handler.api.V2ApiUtils;
 import org.apache.solr.request.SolrQueryRequest;
@@ -112,8 +114,7 @@ public class CatchAllExceptionMapper implements 
ExceptionMapper<Exception> {
         ResponseUtils.getTypedErrorInfo(
             normalizedException,
             log,
-            solrQueryRequest.getCore() != null
-                && 
solrQueryRequest.getCore().getCoreContainer().hideStackTrace());
+            shouldHideStackTrace(solrQueryRequest, containerRequestContext));
     response.responseHeader.status = response.error.code;
     final String mediaType =
         V2ApiUtils.getMediaTypeFromWtParam(
@@ -121,6 +122,16 @@ public class CatchAllExceptionMapper implements 
ExceptionMapper<Exception> {
     return 
Response.status(response.error.code).type(mediaType).entity(response).build();
   }
 
+  static boolean shouldHideStackTrace(
+      SolrQueryRequest solrQueryRequest, ContainerRequestContext 
containerRequestContext) {
+    if (solrQueryRequest != null && solrQueryRequest.getCore() != null) {
+      return solrQueryRequest.getCore().getCoreContainer().hideStackTrace();
+    }
+    final CoreContainer coreContainer =
+        (CoreContainer) containerRequestContext.getProperty(CORE_CONTAINER);
+    return coreContainer != null && coreContainer.hideStackTrace();
+  }
+
   private Response processWebApplicationException(WebApplicationException wae) 
{
     return wae.getResponse();
   }
diff --git 
a/solr/core/src/test/org/apache/solr/servlet/CatchAllExceptionMapperTest.java 
b/solr/core/src/test/org/apache/solr/servlet/CatchAllExceptionMapperTest.java
new file mode 100644
index 00000000000..659c1c9d4ab
--- /dev/null
+++ 
b/solr/core/src/test/org/apache/solr/servlet/CatchAllExceptionMapperTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.servlet;
+
+import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
+import org.apache.solr.common.util.EnvUtils;
+import org.apache.solr.util.SolrJettyTestRule;
+import org.eclipse.jetty.client.StringRequestContent;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+/** SOLR-18066: JAX-RS API ignores hideStackTrace */
+@SuppressSSL
+public class CatchAllExceptionMapperTest extends SolrTestCaseJ4 {
+
+  @ClassRule public static final SolrJettyTestRule solrTestRule = new 
SolrJettyTestRule();
+
+  @BeforeClass
+  public static void setupSolrHome() throws Exception {
+    Path solrHome = createTempDir("solrhome");
+    Files.writeString(
+        solrHome.resolve("solr.xml"),
+        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+            + "<solr>\n"
+            + "  <bool name=\"hideStackTrace\">true</bool>\n"
+            + "</solr>\n");
+    EnvUtils.setProperty(ALLOW_PATHS_SYSPROP, 
solrHome.toAbsolutePath().toString());
+    solrTestRule.startSolr(solrHome);
+  }
+
+  @Test
+  public void testHideStackTraceIsRespectedForCorelessV2Endpoints() throws 
Exception {
+    // Sending a single object instead of the required List<LogLevelChange> 
triggers a
+    // MismatchedInputException through CatchAllExceptionMapper on a coreless 
node-level endpoint.
+    final String url = solrTestRule.getJetty().getBaseURLV2().toString() + 
"/node/logging/levels";
+    var httpClient = solrTestRule.getJetty().getSolrClient().getHttpClient();
+    var response =
+        httpClient
+            .newRequest(url)
+            .method("PUT")
+            .body(
+                new StringRequestContent(
+                    "application/json",
+                    "{\"logger\": \"org.apache.solr\", \"level\": \"DEBUG\"}",
+                    StandardCharsets.UTF_8))
+            .send();
+
+    String body = response.getContentAsString();
+    assertEquals(500, response.getStatus());
+    assertTrue(body.contains("MismatchedInputException"));
+    assertFalse(body.contains("\"trace\""));
+  }
+}

Reply via email to