Author: markt Date: Thu Apr 6 15:20:00 2017 New Revision: 1790420 URL: http://svn.apache.org/viewvc?rev=1790420&view=rev Log: Partial fix for https://bz.apache.org/bugzilla/show_bug.cgi?id=47214 Refactor to remove a switch statement that resulted in the generation of a synthetic class that needed to be pre-loaded
Modified: tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java tomcat/trunk/java/org/apache/catalina/valves/AbstractAccessLogValve.java tomcat/trunk/test/org/apache/catalina/security/TestSecurityClassLoad.java Modified: tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java?rev=1790420&r1=1790419&r2=1790420&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java (original) +++ tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java Thu Apr 6 15:20:00 2017 @@ -46,7 +46,6 @@ public final class SecurityClassLoad { loadServletsPackage(loader); loadSessionPackage(loader); loadUtilPackage(loader); - loadValvesPackage(loader); loadJavaxPackage(loader); loadConnectorPackage(loader); loadTomcatPackage(loader); @@ -156,13 +155,6 @@ public final class SecurityClassLoad { } - private static final void loadValvesPackage(ClassLoader loader) - throws Exception { - final String basePackage = "org.apache.catalina.valves."; - loader.loadClass(basePackage + "AbstractAccessLogValve$3"); - } - - private static final void loadCoyotePackage(ClassLoader loader) throws Exception { final String basePackage = "org.apache.coyote."; Modified: tomcat/trunk/java/org/apache/catalina/valves/AbstractAccessLogValve.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/AbstractAccessLogValve.java?rev=1790420&r1=1790419&r2=1790420&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/valves/AbstractAccessLogValve.java (original) +++ tomcat/trunk/java/org/apache/catalina/valves/AbstractAccessLogValve.java Thu Apr 6 15:20:00 2017 @@ -1010,17 +1010,22 @@ public abstract class AbstractAccessLogV if (usesBegin) { timestamp -= time; } - switch (type) { - case CLF: + /* 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)); - break; - case SEC: + } else if (type == FormatType.SEC) { buf.append(Long.toString(timestamp / 1000)); - break; - case MSEC: + } else if (type == FormatType.MSEC) { buf.append(Long.toString(timestamp)); - break; - case MSEC_FRAC: + } else if (type == FormatType.MSEC_FRAC) { frac = timestamp % 1000; if (frac < 100) { if (frac < 10) { @@ -1031,8 +1036,8 @@ public abstract class AbstractAccessLogV } } buf.append(Long.toString(frac)); - break; - case SDF: + } else { + // FormatType.SDF String temp = localDateCache.get().getFormat(format, locale, timestamp); if (usesMsecs) { frac = timestamp % 1000; @@ -1050,7 +1055,6 @@ public abstract class AbstractAccessLogV temp = temp.replace(msecPattern, Long.toString(frac)); } buf.append(temp); - break; } } } Modified: tomcat/trunk/test/org/apache/catalina/security/TestSecurityClassLoad.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/security/TestSecurityClassLoad.java?rev=1790420&r1=1790419&r2=1790420&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/security/TestSecurityClassLoad.java (original) +++ tomcat/trunk/test/org/apache/catalina/security/TestSecurityClassLoad.java Thu Apr 6 15:20:00 2017 @@ -22,11 +22,6 @@ public class TestSecurityClassLoad { @Test public void testLoad() throws Exception { - // Note that this will fail if you run it from within Eclipse. This is - // because one of the loaded classes (AccessLogValve$3) is a synthetic - // class generated by javac but not by the JDT compiler. Behaviour with - // other IDEs is currently unknown. - SecurityClassLoad.securityClassLoad( - Thread.currentThread().getContextClassLoader(), false); + SecurityClassLoad.securityClassLoad(Thread.currentThread().getContextClassLoader(), false); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org