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

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

commit 5b698b390f411d6c35a0ae6cce45d0f2eb17b286
Author: opencode <[email protected]>
AuthorDate: Fri Oct 16 11:55:30 2026 +0200

    Harmonize resource bundle processing in ProxyErrorReportValve
    
    The redirect url lookup of ProxyErrorReportValve passed the response
    locale straight to ResourceBundle.getBundle(). The StringManager locale
    processing introduced by commit c45c9b47f3 handles this differently: a
    bundle is only loaded for a locale for which a bundle actually exists,
    checked with a cache free probe.
    
    Align the valve with that processing. Resolve the response locale
    through the candidate locales of the default control, check each
    candidate with StringManager.bundleExists() and only then load the
    bundle for the first matching candidate. Locales that match no
    candidate fall back to the default error report as before. To allow the
    reuse, make bundleExists() in StringManager accessible outside the
    class. For the documented layout, a properties file at the root of the
    class path, the resolution is unchanged for every locale.
---
 .../catalina/valves/ProxyErrorReportValve.java     | 23 +++++++++++++++++++++-
 java/org/apache/tomcat/util/res/StringManager.java |  2 +-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/valves/ProxyErrorReportValve.java 
b/java/org/apache/catalina/valves/ProxyErrorReportValve.java
index a61faeb01f..52da5e0e97 100644
--- a/java/org/apache/catalina/valves/ProxyErrorReportValve.java
+++ b/java/org/apache/catalina/valves/ProxyErrorReportValve.java
@@ -25,6 +25,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLEncoder;
+import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -57,6 +58,13 @@ public class ProxyErrorReportValve extends ErrorReportValve {
     private static final int PROXY_CONNECT_TIMEOUT_MS = 5000;
     private static final int PROXY_READ_TIMEOUT_MS = 10000;
 
+    /*
+     * Control used to resolve the candidate locales of the optional 
properties file bundle. The default control is the
+     * one getBundle() uses, so the candidate chain matches the one 
getBundle() would walk.
+     */
+    private static final ResourceBundle.Control BUNDLE_CONTROL =
+            
ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_PROPERTIES);
+
     /**
      * Default constructor.
      */
@@ -111,9 +119,22 @@ public class ProxyErrorReportValve extends 
ErrorReportValve {
     }
 
     private String getRedirectUrl(Response response) {
+        String bundleName = this.getClass().getSimpleName();
+        // Resolve the bundle for the first candidate locale for which a 
bundle exists.
+        Locale bundleLocale = null;
+        for (Locale candidate : BUNDLE_CONTROL.getCandidateLocales(bundleName, 
response.getLocale())) {
+            if (StringManager.bundleExists(bundleName, candidate)) {
+                bundleLocale = candidate;
+                break;
+            }
+        }
+        if (bundleLocale == null) {
+            // No bundle available. Fall back to the default error report.
+            return null;
+        }
         ResourceBundle resourceBundle;
         try {
-            resourceBundle = 
ResourceBundle.getBundle(this.getClass().getSimpleName(), response.getLocale());
+            resourceBundle = ResourceBundle.getBundle(bundleName, 
bundleLocale);
         } catch (MissingResourceException e) {
             // No bundle available. Fall back to the default error report.
             return null;
diff --git a/java/org/apache/tomcat/util/res/StringManager.java 
b/java/org/apache/tomcat/util/res/StringManager.java
index 551db83c01..dfc8488511 100644
--- a/java/org/apache/tomcat/util/res/StringManager.java
+++ b/java/org/apache/tomcat/util/res/StringManager.java
@@ -300,7 +300,7 @@ public class StringManager {
      *
      * @return true if a bundle exists for the given locale
      */
-    private static boolean bundleExists(String bundleName, Locale locale) {
+    public static boolean bundleExists(String bundleName, Locale locale) {
         ClassLoader classLoader = StringManager.class.getClassLoader();
         if (bundleExists(bundleName, locale, classLoader)) {
             return true;


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

Reply via email to