Author: markt Date: Tue Jun 24 14:42:27 2008 New Revision: 671358 URL: http://svn.apache.org/viewvc?rev=671358&view=rev Log: Make coercion of "" and null to zero in EL configurable
Modified: tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/el/parser/AstValue.java tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml Modified: tomcat/tc6.0.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=671358&r1=671357&r2=671358&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Tue Jun 24 14:42:27 2008 @@ -41,17 +41,6 @@ +1: markt, remm -1: -* Make fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=43285 optional - Coercion of null and "" to zero can now be disabled if required - Patch by Nils Eckert - http://svn.apache.org/viewvc?rev=665756&view=rev - +1: markt, remm - +1: fhanik - candidate for STRICT_SERVLET_COMPLIANCE? - markt - Probably not. STRICT_SERVLET_COMPLIANCE is a shortcut to set all - options that are non-compliant by default. This one is already - compliant by defult - -1: - * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45195 NPE when calling getAttribute(null). The spec is unclear but this is a regression from 5.0.x. Also avoid NPE on remove. Modified: tomcat/tc6.0.x/trunk/java/org/apache/el/parser/AstValue.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/el/parser/AstValue.java?rev=671358&r1=671357&r2=671358&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/el/parser/AstValue.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/el/parser/AstValue.java Tue Jun 24 14:42:27 2008 @@ -38,6 +38,10 @@ */ public final class AstValue extends SimpleNode { + protected static final boolean COERCE_TO_ZERO = + Boolean.valueOf(System.getProperty( + "org.apache.el.parser.COERCE_TO_ZERO", "true")).booleanValue(); + protected static class Target { protected Object base; @@ -129,12 +133,28 @@ Target t = getTarget(ctx); ctx.setPropertyResolved(false); ELResolver resolver = ctx.getELResolver(); - resolver.setValue(ctx, t.base, t.property, - // coerce to the expected type - ELSupport.coerceToType(value, - resolver.getType(ctx, t.base, t.property))); + + // coerce to the expected type + Class<?> targetClass = resolver.getType(ctx, t.base, t.property); + if (COERCE_TO_ZERO == true + || !isAssignable(value, targetClass)) { + value = ELSupport.coerceToType(value, targetClass); + } + resolver.setValue(ctx, t.base, t.property, value); + } + + private boolean isAssignable(Object value, Class<?> targetClass) { + if (targetClass == null) { + return false; + } else if (value != null && targetClass.isPrimitive()) { + return false; + } else if (value != null && !targetClass.isInstance(value)) { + return false; + } + return true; } + public MethodInfo getMethodInfo(EvaluationContext ctx, Class[] paramTypes) throws ELException { Target t = getTarget(ctx); Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=671358&r1=671357&r2=671358&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Tue Jun 24 14:42:27 2008 @@ -86,6 +86,13 @@ <bug>43150</bug>: Allow Tomcat to start correctly when installed on a path that contains a # character. (markt) </fix> + <add> + The fix for <bug>43285</bug> had the side-effct of coercing + <code>null</code> values to zero. This side-effect has been made + configurable with a system property, + <code>org.apache.el.parser.COERCE_TO_ZERO</code> which defaults to + <code>true</code>. Patch provided by Nils Eckert. (markt) + </add> <fix> <bug>43343</bug>: Correctly handle requesting a session we are in the middle of persisting. Based on a suggestion by Wade Chandler. (markt) Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml?rev=671358&r1=671357&r2=671358&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml Tue Jun 24 14:42:27 2008 @@ -48,6 +48,18 @@ </section> +<section name="Expression Language"> + <properties> + + <property name="org.apache.el.parser.COERCE_TO_ZERO"> + <p>If <code>true</code>, when coercing expressions to numbers + <code>""</code> and <code>null</code> will be coerced to zero as required + by the specification. If not specified, the default value of + <code>true</code> will be used.</p> + </property> + + </properties> +</section> <section name="Jasper"> <properties> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]