Author: markt Date: Fri Oct 26 18:16:19 2012 New Revision: 1402604 URL: http://svn.apache.org/viewvc?rev=1402604&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54044 Add test case for BZ 54044
Added: tomcat/tc7.0.x/trunk/test/org/apache/catalina/valves/TestAccessLogValve.java - copied unchanged from r1402601, tomcat/trunk/test/org/apache/catalina/valves/TestAccessLogValve.java Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1402573,1402576,1402600-1402601 Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java?rev=1402604&r1=1402603&r2=1402604&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java Fri Oct 26 18:16:19 2012 @@ -301,28 +301,28 @@ public class AccessLogValve extends Valv * <p>This class uses a small thread local first level cache and a bigger * synchronized global second level cache.</p> */ - private static class DateFormatCache { + protected static class DateFormatCache { - private class Cache { + protected class Cache { /* CLF log format */ private static final String cLFFormat = "dd/MMM/yyyy:HH:mm:ss"; /* Second used to retrieve CLF format in most recent invocation */ - private long previousSeconds = 0L; + private long previousSeconds = Long.MIN_VALUE; /* Value of CLF format retrieved in most recent invocation */ private String previousFormat = ""; /* First second contained in cache */ - private long first = 0L; + private long first = Long.MIN_VALUE; /* Last second contained in cache */ - private long last = 0L; + private long last = Long.MIN_VALUE; /* Index of "first" in the cyclic cache */ private int offset = 0; /* Helper object to be able to call SimpleDateFormat.format(). */ private final Date currentDate = new Date(); - private final String cache[]; + protected final String cache[]; private SimpleDateFormat formatter; private boolean isCLF = false; @@ -391,14 +391,16 @@ public class AccessLogValve extends Valv for (int i = 1; i < seconds - last; i++) { cache[(index + cacheSize - i) % cacheSize] = null; } - first = seconds - cacheSize; + first = seconds - (cacheSize - 1); last = seconds; + offset = (index + 1) % cacheSize; } else if (seconds < first) { for (int i = 1; i < first - seconds; i++) { cache[(index + i) % cacheSize] = null; } first = seconds; - last = seconds + cacheSize; + last = seconds + (cacheSize - 1); + offset = index; } /* Last step: format new timestamp either using @@ -430,10 +432,10 @@ public class AccessLogValve extends Valv private final Locale cacheDefaultLocale; private final DateFormatCache parent; - private final Cache cLFCache; + protected final Cache cLFCache; private final HashMap<String, Cache> formatCache = new HashMap<String, Cache>(); - private DateFormatCache(int size, Locale loc, DateFormatCache parent) { + protected DateFormatCache(int size, Locale loc, DateFormatCache parent) { cacheSize = size; cacheDefaultLocale = loc; this.parent = parent; @@ -497,8 +499,7 @@ public class AccessLogValve extends Valv * The system time when we last updated the Date that this valve * uses for log lines. */ - private static final ThreadLocal<Date> localDate = - new ThreadLocal<Date>() { + private static final ThreadLocal<Date> localDate = new ThreadLocal<Date>() { @Override protected Date initialValue() { return new Date(); @@ -1128,11 +1129,8 @@ public class AccessLogValve extends Valv } /** - * This method returns a Date object that is accurate to within one second. - * If a thread calls this method to get a Date and it's been less than 1 - * second since a new Date was created, this method simply gives out the - * same Date again so that the system doesn't spend time creating Date - * objects unnecessarily. + * This method returns a ThreadLocal Date object that is set to the + * specified time. This saves creating a new Date object for every request. * * @return Date */ Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1402604&r1=1402603&r2=1402604&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Fri Oct 26 18:16:19 2012 @@ -68,6 +68,11 @@ Update MIME type mapping with additional / updated mime.types from the Apache web server. (markt) </add> + <fix> + <bug>54044</bug>: Correct bug in timestamp cache for access log valve + that meant entries could be made with a much earlier timestamp than the + true timestamp. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org