*/
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;
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);
</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>