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

rmaucher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 67377c65a47e7cc14aae01154655f5d32be0860e
Author: opencode <[email protected]>
AuthorDate: Mon Oct 12 11:46:26 2026 +0200

    Fall back to the default error report when the properties bundle is absent
    
    With usePropertiesFile set to true, getRedirectUrl() called
    ResourceBundle.getBundle() without guarding against
    MissingResourceException, which is thrown when no
    ProxyErrorReportValve bundle can be found for any candidate locale. The
    exception propagated out of report() and was silently swallowed by the
    blanket catch in ErrorReportValve.invoke(), so every error report was
    dropped and the client received an empty response carrying only the
    error status.
    
    Catch the exception in getRedirectUrl() and return null so the existing
    null-URL check in report() falls through to the default error report of
    the parent ErrorReportValve. Add a test that enables usePropertiesFile
    with no bundle on the class path and asserts the default HTML error
    report is produced.
---
 .../catalina/valves/ProxyErrorReportValve.java     |  8 ++++-
 .../catalina/valves/TestProxyErrorReportValve.java | 40 ++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/valves/ProxyErrorReportValve.java 
b/java/org/apache/catalina/valves/ProxyErrorReportValve.java
index 97b63e8221..14b891834a 100644
--- a/java/org/apache/catalina/valves/ProxyErrorReportValve.java
+++ b/java/org/apache/catalina/valves/ProxyErrorReportValve.java
@@ -111,7 +111,13 @@ public class ProxyErrorReportValve extends 
ErrorReportValve {
     }
 
     private String getRedirectUrl(Response response) {
-        ResourceBundle resourceBundle = 
ResourceBundle.getBundle(this.getClass().getSimpleName(), response.getLocale());
+        ResourceBundle resourceBundle;
+        try {
+            resourceBundle = 
ResourceBundle.getBundle(this.getClass().getSimpleName(), response.getLocale());
+        } catch (MissingResourceException e) {
+            // No bundle available. Fall back to the default error report.
+            return null;
+        }
         String redirectUrl = null;
         try {
             redirectUrl = 
resourceBundle.getString(Integer.toString(response.getStatus()));
diff --git a/test/org/apache/catalina/valves/TestProxyErrorReportValve.java 
b/test/org/apache/catalina/valves/TestProxyErrorReportValve.java
index bbd10da136..298a156281 100644
--- a/test/org/apache/catalina/valves/TestProxyErrorReportValve.java
+++ b/test/org/apache/catalina/valves/TestProxyErrorReportValve.java
@@ -514,6 +514,46 @@ public class TestProxyErrorReportValve extends 
TomcatBaseTest {
     }
 
 
+    @Test
+    public void testMissingPropertiesBundleFallsBackToSuper() throws Exception 
{
+        Tomcat tomcat = getTomcatInstance();
+        ((StandardHost) 
tomcat.getHost()).setErrorReportValveClass(PROXY_VALVE);
+
+        Context ctx = getProgrammaticRootContext();
+
+        Tomcat.addServlet(ctx, "error", new SendErrorServlet(
+                HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Server broke"));
+        ctx.addServletMapping("/", "error");
+
+        tomcat.start();
+
+        ProxyErrorReportValve valve = null;
+        Valve[] valves = tomcat.getHost().getPipeline().getValves();
+        for (Valve valveCandidate : valves) {
+            if (PROXY_VALVE.equals(valveCandidate.getClass().getName())) {
+                valve = (ProxyErrorReportValve)valveCandidate;
+                break;
+            }
+        }
+        Assert.assertNotNull(valve);
+        // No ProxyErrorReportValve.properties bundle is available on the
+        // test class path. The default error report must be produced rather
+        // than an empty response.
+        valve.setUsePropertiesFile(true);
+
+        ByteChunk res = new ByteChunk();
+        int rc = getUrl("http://localhost:"; + getPort(), res, null);
+
+        Assert.assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
+
+        String body = res.toString();
+        Assert.assertNotNull("Response body should not be empty", body);
+        Assert.assertTrue("Should contain HTML error report",
+                body.contains("html") &&
+                    
body.contains(String.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)));
+    }
+
+
     private static final class SendErrorServlet extends HttpServlet {
 
         @Serial


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to