This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 19bd0ef48e Use a switch now SecurityManager constraint is not a concern 19bd0ef48e is described below commit 19bd0ef48eae6a417adc9f972f42d569851a2c08 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Jan 19 17:00:44 2023 +0000 Use a switch now SecurityManager constraint is not a concern --- .../catalina/valves/AbstractAccessLogValve.java | 77 ++++++++++------------ 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/java/org/apache/catalina/valves/AbstractAccessLogValve.java b/java/org/apache/catalina/valves/AbstractAccessLogValve.java index 879da82d5d..73852569fa 100644 --- a/java/org/apache/catalina/valves/AbstractAccessLogValve.java +++ b/java/org/apache/catalina/valves/AbstractAccessLogValve.java @@ -1140,58 +1140,53 @@ public abstract class AbstractAccessLogValve extends ValveBase implements Access } @Override - public void addElement(CharArrayWriter buf, Date date, Request request, - Response response, long time) { + public void addElement(CharArrayWriter buf, Date date, Request request, Response response, long time) { long timestamp = date.getTime(); long frac; if (!usesBegin) { timestamp += TimeUnit.NANOSECONDS.toMillis(time); } - /* Implementation note: This is deliberately not implemented using - * switch. If a switch is used the compiler (at least the Oracle - * one) will use a synthetic class to implement the switch. The - * problem is that this class needs to be pre-loaded when using a - * SecurityManager and the name of that class will depend on any - * anonymous inner classes and any other synthetic classes. As such - * the name is not constant and keeping the pre-loading up to date - * as the name changes is error prone. - */ - if (type == FormatType.CLF) { - buf.append(localDateCache.get().getFormat(timestamp)); - } else if (type == FormatType.SEC) { - buf.append(Long.toString(timestamp / 1000)); - } else if (type == FormatType.MSEC) { - buf.append(Long.toString(timestamp)); - } else if (type == FormatType.MSEC_FRAC) { - frac = timestamp % 1000; - if (frac < 100) { - if (frac < 10) { - buf.append('0'); - buf.append('0'); - } else { - buf.append('0'); - } - } - buf.append(Long.toString(frac)); - } else { - // FormatType.SDF - String temp = localDateCache.get().getFormat(format, locale, timestamp); - if (usesMsecs) { + switch (type) { + case CLF: + buf.append(localDateCache.get().getFormat(timestamp)); + break; + case SEC: + buf.append(Long.toString(timestamp / 1000)); + break; + case MSEC: + buf.append(Long.toString(timestamp)); + break; + case MSEC_FRAC: frac = timestamp % 1000; - StringBuilder tripleMsec = new StringBuilder(4); if (frac < 100) { if (frac < 10) { - tripleMsec.append('0'); - tripleMsec.append('0'); + buf.append('0'); + buf.append('0'); } else { - tripleMsec.append('0'); + buf.append('0'); } } - tripleMsec.append(frac); - temp = temp.replace(tripleMsecPattern, tripleMsec); - temp = temp.replace(msecPattern, Long.toString(frac)); - } - buf.append(temp); + buf.append(Long.toString(frac)); + break; + case SDF: + String temp = localDateCache.get().getFormat(format, locale, timestamp); + if (usesMsecs) { + frac = timestamp % 1000; + StringBuilder tripleMsec = new StringBuilder(4); + if (frac < 100) { + if (frac < 10) { + tripleMsec.append('0'); + tripleMsec.append('0'); + } else { + tripleMsec.append('0'); + } + } + tripleMsec.append(frac); + temp = temp.replace(tripleMsecPattern, tripleMsec); + temp = temp.replace(msecPattern, Long.toString(frac)); + } + buf.append(temp); + break; } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org