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

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


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 130c3a033b Cleanups
130c3a033b is described below

commit 130c3a033bd4a48618b53a09f33c7c0547e61a15
Author: remm <r...@apache.org>
AuthorDate: Wed Mar 12 12:14:05 2025 +0100

    Cleanups
---
 .../catalina/valves/AbstractAccessLogValve.java    | 38 +++++++++-------------
 .../org/apache/catalina/valves/AccessLogValve.java |  6 ++--
 .../catalina/valves/ExtendedAccessLogValve.java    | 24 +++++++-------
 3 files changed, 29 insertions(+), 39 deletions(-)

diff --git a/java/org/apache/catalina/valves/AbstractAccessLogValve.java 
b/java/org/apache/catalina/valves/AbstractAccessLogValve.java
index 5dde798b64..de91435ed6 100644
--- a/java/org/apache/catalina/valves/AbstractAccessLogValve.java
+++ b/java/org/apache/catalina/valves/AbstractAccessLogValve.java
@@ -257,11 +257,11 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
             /* Helper object to be able to call SimpleDateFormat.format(). */
             private final Date currentDate = new Date();
 
-            protected final String cache[];
-            private SimpleDateFormat formatter;
+            protected final String[] cache;
+            private final SimpleDateFormat formatter;
             private boolean isCLF = false;
 
-            private Cache parent = null;
+            private final Cache parent;
 
             private Cache(Cache parent) {
                 this(null, parent);
@@ -351,11 +351,7 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
                     currentDate.setTime(time);
                     previousFormat = formatter.format(currentDate);
                     if (isCLF) {
-                        StringBuilder current = new StringBuilder(32);
-                        current.append('[');
-                        current.append(previousFormat);
-                        current.append(']');
-                        previousFormat = current.toString();
+                        previousFormat = "[" + previousFormat + "]";
                     }
                 }
                 cache[index] = previousFormat;
@@ -371,10 +367,10 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
         protected final Cache cLFCache;
         private final Map<String,Cache> formatCache = new HashMap<>();
 
-        protected DateFormatCache(int size, Locale loc, DateFormatCache 
parent) {
+        protected DateFormatCache(int size, Locale loc, DateFormatCache 
parentFC) {
             cacheSize = size;
             cacheDefaultLocale = loc;
-            this.parent = parent;
+            parent = parentFC;
             Cache parentCache = null;
             if (parent != null) {
                 synchronized (parent) {
@@ -473,7 +469,7 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
     /**
      * Buffer pool used for log message generation. Pool used to reduce 
garbage generation.
      */
-    private SynchronizedStack<CharArrayWriter> charArrayWriters = new 
SynchronizedStack<>();
+    private final SynchronizedStack<CharArrayWriter> charArrayWriters = new 
SynchronizedStack<>();
 
     /**
      * Log message buffers are usually recycled and re-used. To prevent 
excessive memory usage, if a buffer grows beyond
@@ -891,10 +887,10 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
                     value = host.toString();
                 }
             }
-            if (value == null || value.length() == 0) {
+            if (value == null || value.isEmpty()) {
                 value = request.getRemoteHost();
             }
-            if (value == null || value.length() == 0) {
+            if (value == null || value.isEmpty()) {
                 value = "-";
             }
 
@@ -1070,7 +1066,7 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
                     usesBegin = false;
                     format = format.substring(4);
                 }
-                if (format.length() == 0) {
+                if (format.isEmpty()) {
                     type = FormatType.CLF;
                 } else if (format.equals(secFormat)) {
                     type = FormatType.SEC;
@@ -1108,11 +1104,9 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
                 case MSEC_FRAC:
                     frac = timestamp % 1000;
                     if (frac < 100) {
+                        buf.append('0');
                         if (frac < 10) {
                             buf.append('0');
-                            buf.append('0');
-                        } else {
-                            buf.append('0');
                         }
                     }
                     buf.append(Long.toString(frac));
@@ -1123,11 +1117,9 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
                         frac = timestamp % 1000;
                         StringBuilder tripleMsec = new StringBuilder(4);
                         if (frac < 100) {
+                            tripleMsec.append('0');
                             if (frac < 10) {
                                 tripleMsec.append('0');
-                                tripleMsec.append('0');
-                            } else {
-                                tripleMsec.append('0');
                             }
                         }
                         tripleMsec.append(frac);
@@ -1457,10 +1449,10 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
                     value = serverName.toString();
                 }
             }
-            if (value == null || value.length() == 0) {
+            if (value == null || value.isEmpty()) {
                 value = request.getServerName();
             }
-            if (value == null || value.length() == 0) {
+            if (value == null || value.isEmpty()) {
                 value = "-";
             }
 
@@ -1768,7 +1760,7 @@ public abstract class AbstractAccessLogValve extends 
ValveBase implements Access
                 buf.append(ch);
             }
         }
-        if (buf.length() > 0) {
+        if (!buf.isEmpty()) {
             list.add(new StringElement(buf.toString()));
         }
         return list.toArray(new AccessLogElement[0]);
diff --git a/java/org/apache/catalina/valves/AccessLogValve.java 
b/java/org/apache/catalina/valves/AccessLogValve.java
index 1251a7be5a..fdaac8033b 100644
--- a/java/org/apache/catalina/valves/AccessLogValve.java
+++ b/java/org/apache/catalina/valves/AccessLogValve.java
@@ -345,7 +345,7 @@ public class AccessLogValve extends AbstractAccessLogValve {
      * @param encoding The name of the character set.
      */
     public void setEncoding(String encoding) {
-        if (encoding != null && encoding.length() > 0) {
+        if (encoding != null && !encoding.isEmpty()) {
             this.encoding = encoding;
         } else {
             this.encoding = null;
@@ -377,14 +377,14 @@ public class AccessLogValve extends 
AbstractAccessLogValve {
                     for (String oldAccessLog : oldAccessLogs) {
                         boolean match = false;
 
-                        if (prefix != null && prefix.length() > 0) {
+                        if (prefix != null && !prefix.isEmpty()) {
                             if (!oldAccessLog.startsWith(prefix)) {
                                 continue;
                             }
                             match = true;
                         }
 
-                        if (suffix != null && suffix.length() > 0) {
+                        if (suffix != null && !suffix.isEmpty()) {
                             if (!oldAccessLog.endsWith(suffix)) {
                                 continue;
                             }
diff --git a/java/org/apache/catalina/valves/ExtendedAccessLogValve.java 
b/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
index e5483ecbad..da63bf2b74 100644
--- a/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
+++ b/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
@@ -41,8 +41,9 @@ import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.ExceptionUtils;
 
 /**
- * An implementation of the W3c Extended Log File Format. See 
http://www.w3.org/TR/WD-logfile.html for more information
- * about the format. The following fields are supported:
+ * An implementation of the W3c Extended Log File Format. See
+ * <a href="http://www.w3.org/TR/WD-logfile.html";>WD-logfile-960323</a>
+ * for more information about the format. The following fields are supported:
  * <ul>
  * <li><code>c-dns</code>: Client hostname (or ip address if 
<code>enableLookups</code> for the connector is false)</li>
  * <li><code>c-ip</code>: Client ip address</li>
@@ -235,7 +236,7 @@ public class ExtendedAccessLogValve extends AccessLogValve {
                     value.append(c[i].getValue());
                 }
             }
-            if (value.length() == 0) {
+            if (value.isEmpty()) {
                 buf.append('-');
             } else {
                 wrap(value, buf);
@@ -321,7 +322,7 @@ public class ExtendedAccessLogValve extends AccessLogValve {
          * urlEncode the given string. If null or empty, return null.
          */
         private String urlEncode(String value) {
-            if (null == value || value.length() == 0) {
+            if (null == value || value.isEmpty()) {
                 return null;
             }
             return URLEncoder.QUERY.encode(value, StandardCharsets.UTF_8);
@@ -393,7 +394,7 @@ public class ExtendedAccessLogValve extends AccessLogValve {
                 c = sr.read();
             }
             ended = true;
-            if (buf.length() != 0) {
+            if (!buf.isEmpty()) {
                 return buf.toString();
             } else {
                 return null;
@@ -424,7 +425,7 @@ public class ExtendedAccessLogValve extends AccessLogValve {
                 return "";
             }
             StringBuilder whiteSpaces = new StringBuilder();
-            if (buf.length() > 0) {
+            if (!buf.isEmpty()) {
                 whiteSpaces.append(buf);
                 buf = new StringBuilder();
             }
@@ -484,7 +485,7 @@ public class ExtendedAccessLogValve extends AccessLogValve {
                 }
                 list.add(element);
                 String whiteSpaces = tokenizer.getWhiteSpaces();
-                if (whiteSpaces.length() > 0) {
+                if (!whiteSpaces.isEmpty()) {
                     list.add(new StringElement(whiteSpaces));
                 }
                 if (tokenizer.isEnded()) {
@@ -604,10 +605,8 @@ public class ExtendedAccessLogValve extends AccessLogValve 
{
                         public void addElement(CharArrayWriter buf, Date date, 
Request request, Response response,
                                 long time) {
                             String query = request.getQueryString();
-                            if (query == null) {
-                                buf.append(request.getRequestURI());
-                            } else {
-                                buf.append(request.getRequestURI());
+                            buf.append(request.getRequestURI());
+                            if (query != null) {
                                 buf.append('?');
                                 buf.append(request.getQueryString());
                             }
@@ -648,7 +647,6 @@ public class ExtendedAccessLogValve extends AccessLogValve {
     }
 
     protected AccessLogElement getProxyElement(PatternTokenizer tokenizer) 
throws IOException {
-        String token = null;
         if (tokenizer.hasSubToken()) {
             tokenizer.getToken();
             return new StringElement("-");
@@ -656,7 +654,7 @@ public class ExtendedAccessLogValve extends AccessLogValve {
             tokenizer.getParameter();
             return new StringElement("-");
         }
-        log.error(sm.getString("extendedAccessLogValve.decodeError", token));
+        log.error(sm.getString("extendedAccessLogValve.decodeError", 
tokenizer.getRemains()));
         return null;
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to