Author: markt Date: Wed May 14 21:20:40 2014 New Revision: 1594723 URL: http://svn.apache.org/r1594723 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56522 When setting a value for a ValueExpression, ensure that the expected coercions take place such as a null string being coerced to an empty string.
Modified: tomcat/trunk/java/org/apache/el/parser/AstValue.java tomcat/trunk/test/org/apache/el/TestValueExpressionImpl.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/el/parser/AstValue.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstValue.java?rev=1594723&r1=1594722&r2=1594723&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/el/parser/AstValue.java (original) +++ tomcat/trunk/java/org/apache/el/parser/AstValue.java Wed May 14 21:20:40 2014 @@ -197,30 +197,14 @@ public final class AstValue extends Simp // coerce to the expected type Class<?> targetClass = resolver.getType(ctx, t.base, t.property); - if (!isAssignable(value, targetClass)) { - resolver.setValue(ctx, t.base, t.property, - ELSupport.coerceToType(value, targetClass)); - } else { - resolver.setValue(ctx, t.base, t.property, value); - } + resolver.setValue(ctx, t.base, t.property, + ELSupport.coerceToType(value, targetClass)); if (!ctx.isPropertyResolved()) { throw new PropertyNotFoundException(MessageFactory.get( "error.resolver.unhandled", t.base, t.property)); } } - 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; - } - - @Override // Interface el.parser.Node uses raw types (and is auto-generated) public MethodInfo getMethodInfo(EvaluationContext ctx, Modified: tomcat/trunk/test/org/apache/el/TestValueExpressionImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/TestValueExpressionImpl.java?rev=1594723&r1=1594722&r2=1594723&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/el/TestValueExpressionImpl.java (original) +++ tomcat/trunk/test/org/apache/el/TestValueExpressionImpl.java Wed May 14 21:20:40 2014 @@ -241,4 +241,29 @@ public class TestValueExpressionImpl { Integer result = (Integer) ve.getValue(context); assertEquals(Integer.valueOf(0), result); } + + + @Test + public void testBug56522SetNullValue() { + ExpressionFactory factory = ExpressionFactory.newInstance(); + ELContext context = new ELContextImpl(factory); + + TesterBeanB beanB = new TesterBeanB(); + beanB.setName("Tomcat"); + ValueExpression var = + factory.createValueExpression(beanB, TesterBeanB.class); + context.getVariableMapper().setVariable("beanB", var); + + ValueExpression ve = factory.createValueExpression( + context, "${beanB.name}", String.class); + + // First check the basics work + String result = (String) ve.getValue(context); + assertEquals("Tomcat", result); + + // Now set the value to null + ve.setValue(context, null); + + assertEquals("", beanB.getName()); + } } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1594723&r1=1594722&r2=1594723&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Wed May 14 21:20:40 2014 @@ -44,6 +44,18 @@ They eventually become mixed with the numbered issues. (I.e., numbered issues to not "pop up" wrt. others). --> +<section name="Tomcat 8.0.7 (markt)"> + <subsection name="Jasper"> + <changelog> + <fix> + <bug>56522</bug>: When setting a value for a + <code>ValueExpression</code>, ensure that the expected coercions take + place such as a <code>null</code> string being coerced to an empty + string. (markt) + </fix> + </changelog> + </subsection> +</section> <section name="Tomcat 8.0.6 (markt)"> <subsection name="Catalina"> <changelog> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org