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

markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new 3f04aa59c0 Wrap debug log calls.
3f04aa59c0 is described below

commit 3f04aa59c0ee153afe73fc1487d1b3c47e29a2ef
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Oct 1 17:43:09 2026 +0100

    Wrap debug log calls.
    
    It is arguable is isn't necessary to wrap them all, but wrap them all
    for consistency.
---
 .../apache/catalina/filters/RemoteIpFilter.java    | 38 +++++++++++++++-------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/java/org/apache/catalina/filters/RemoteIpFilter.java 
b/java/org/apache/catalina/filters/RemoteIpFilter.java
index 659d96f9bc..fbec035d46 100644
--- a/java/org/apache/catalina/filters/RemoteIpFilter.java
+++ b/java/org/apache/catalina/filters/RemoteIpFilter.java
@@ -473,8 +473,8 @@ public class RemoteIpFilter extends GenericFilter {
     private static final long serialVersionUID = 1L;
 
     /**
-     * Wrapper for {@link HttpServletRequest} that allows modification of 
headers, remote address,
-     * scheme, and other properties used by the RemoteIpFilter.
+     * Wrapper for {@link HttpServletRequest} that allows modification of 
headers, remote address, scheme, and other
+     * properties used by the RemoteIpFilter.
      */
     public static class XForwardedRequest extends HttpServletRequestWrapper {
 
@@ -566,6 +566,7 @@ public class RemoteIpFilter extends GenericFilter {
          * Find the header entry for the given name (case-insensitive).
          *
          * @param name the header name to look up
+         *
          * @return the header entry, or {@code null} if not found
          */
         protected Map.Entry<String,List<String>> getHeaderEntry(String name) {
@@ -650,7 +651,7 @@ public class RemoteIpFilter extends GenericFilter {
         /**
          * Set a header value.
          *
-         * @param name the header name
+         * @param name  the header name
          * @param value the header value
          */
         public void setHeader(String name, String value) {
@@ -923,8 +924,8 @@ public class RemoteIpFilter extends GenericFilter {
     private boolean enableLookups;
 
     /**
-     * Process the incoming request, updating the remote address, scheme, and 
headers based on
-     * the configured forwarded headers when the request comes from a trusted 
proxy.
+     * Process the incoming request, updating the remote address, scheme, and 
headers based on the configured forwarded
+     * headers when the request comes from a trusted proxy.
      *
      * @param request  The servlet request to be processed
      * @param response The servlet response to be created
@@ -990,7 +991,9 @@ public class RemoteIpFilter extends GenericFilter {
                         // We know we need a DNS look up so use 
getCanonicalHostName()
                         
xRequest.setRemoteHost(inetAddress.getCanonicalHostName());
                     } catch (UnknownHostException e) {
-                        
log.debug(sm.getString("remoteIpFilter.invalidRemoteAddress", remoteIp), e);
+                        if (log.isDebugEnabled()) {
+                            
log.debug(sm.getString("remoteIpFilter.invalidRemoteAddress", remoteIp), e);
+                        }
                         xRequest.setRemoteHost(remoteIp);
                     }
                 } else {
@@ -1033,7 +1036,10 @@ public class RemoteIpFilter extends GenericFilter {
                     try {
                         int portIndex = Host.parse(hostHeaderValue);
                         if (portIndex > -1) {
-                            
log.debug(sm.getString("remoteIpFilter.invalidHostWithPort", hostHeaderValue, 
hostHeader));
+                            if (log.isDebugEnabled()) {
+                                
log.debug(sm.getString("remoteIpFilter.invalidHostWithPort", hostHeaderValue,
+                                        hostHeader));
+                            }
                             hostHeaderValue = hostHeaderValue.substring(0, 
portIndex);
                         }
 
@@ -1043,7 +1049,10 @@ public class RemoteIpFilter extends GenericFilter {
                         }
 
                     } catch (IllegalArgumentException iae) {
-                        
log.debug(sm.getString("remoteIpFilter.invalidHostHeader", hostHeaderValue, 
hostHeader), iae);
+                        if (log.isDebugEnabled()) {
+                            
log.debug(sm.getString("remoteIpFilter.invalidHostHeader", hostHeaderValue, 
hostHeader),
+                                    iae);
+                        }
                     }
                 }
             }
@@ -1105,10 +1114,14 @@ public class RemoteIpFilter extends GenericFilter {
                 try {
                     port = Integer.parseInt(portHeaderValue);
                 } catch (NumberFormatException nfe) {
-                    log.debug(sm.getString("remoteIpFilter.invalidPort", 
portHeaderValue, getPortHeader()), nfe);
+                    if (log.isDebugEnabled()) {
+                        log.debug(sm.getString("remoteIpFilter.invalidPort", 
portHeaderValue, getPortHeader()), nfe);
+                    }
                 }
                 if (port < 1 || port > 65535) {
-                    log.debug(sm.getString("remoteIpFilter.invalidPort", 
portHeaderValue, getPortHeader()));
+                    if (log.isDebugEnabled()) {
+                        log.debug(sm.getString("remoteIpFilter.invalidPort", 
portHeaderValue, getPortHeader()));
+                    }
                     port = defaultPort;
                 }
             }
@@ -1524,11 +1537,14 @@ public class RemoteIpFilter extends GenericFilter {
 
     /**
      * Restores the log after deserialization.
+     * <p>
      * Log objects are not Serializable but this Filter is because it extends 
GenericFilter. Tomcat won't serialize a
      * Filter but in case something else does...
+     *
      * @param ois the object input stream
+     *
      * @throws ClassNotFoundException if the class is not found
-     * @throws IOException if an I/O error occurs
+     * @throws IOException            if an I/O error occurs
      */
     private void readObject(ObjectInputStream ois) throws 
ClassNotFoundException, IOException {
         ois.defaultReadObject();


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

Reply via email to