This is an automated email from the ASF dual-hosted git repository. remm 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 64c21e8971 Cleanups 64c21e8971 is described below commit 64c21e89714f75d20be9c7e475050d894768e296 Author: remm <r...@apache.org> AuthorDate: Wed Mar 12 12:14:05 2025 +0100 Cleanups --- .../catalina/valves/AbstractAccessLogValve.java | 22 ++++++++-------------- .../org/apache/catalina/valves/AccessLogValve.java | 6 +++--- .../catalina/valves/ExtendedAccessLogValve.java | 14 ++++++-------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/java/org/apache/catalina/valves/AbstractAccessLogValve.java b/java/org/apache/catalina/valves/AbstractAccessLogValve.java index b704b3a1f0..4992964b27 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 @@ -1126,11 +1122,9 @@ public abstract class AbstractAccessLogValve extends ValveBase implements Access frac = timestamp % 1000; StringBuilder tripleMsec = new StringBuilder(4); if (frac < 100) { + buf.append('0'); if (frac < 10) { tripleMsec.append('0'); - tripleMsec.append('0'); - } else { - tripleMsec.append('0'); } } tripleMsec.append(frac); 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..ae92f440da 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> @@ -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