in velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMathNode.java [86:137]
public Object value(InternalContextAdapter context) throws MethodInvocationException
{
Object left = jjtGetChild(0).value(context);
Object right = jjtGetChild(1).value(context);
/*
* should we do anything special here?
*/
Object special = handleSpecial(left, right, context);
if (special != null)
{
return special;
}
// coerce to Number type, if possible
try
{
left = DuckType.asNumber(left);
}
catch (NumberFormatException nfe) {}
try
{
right = DuckType.asNumber(right);
}
catch (NumberFormatException nfe) {}
/*
* if not a Number, not much we can do
*/
if (!(left instanceof Number) || !(right instanceof Number))
{
boolean wrongright = (left instanceof Number);
boolean wrongtype = wrongright ? right != null : left != null;
String msg = (wrongright ? "Right" : "Left")
+ " side of math operation ("
+ jjtGetChild(wrongright ? 1 : 0).literal() + ") "
+ (wrongtype ? "is not a Number. " : "has a null value. ")
+ getLocation(context);
if (strictMode)
{
log.error(msg);
throw new MathException(msg, rsvc.getLogContext().getStackTrace());
}
else
{
log.debug(msg);
return null;
}
}
return perform((Number)left, (Number)right, context);
}