Details
-
Improvement
-
Status: Closed
-
Critical
-
Resolution: Not A Bug
-
2.1.1, 3.0
-
None
Description
If A String and a Boolean is passed to this method, it throws an expection and just dies.
Booleans (True or False) should be treated just like strings and just concatenated together, so that this would not cause any problems.
Spring jade currently uses this method when it is building html, and if a boolean is used in the string, it causes the parsing to die.
Not sure it is fully the intended purpose, so not reported as a bug, but as a nice improvement, but it sure causing me some stress.
You can easily put the return in the finally, check for boolean or just use the string function to return the string value
/**
- Add two values together.
- <p>
- If any numeric add fails on coercion to the appropriate type,
- treat as Strings and do concatenation.
- </p>
- @param left left argument
- @param right right argument
- @return left + right.
*/
public Object add(Object left, Object right) {
if (left == null && right == null) { return controlNullNullOperands(); }
/***
Possible Fix
if (left instanceof Boolean)
{ left = (Boolean.valueOf((boolean) left).toString()); }if (right instanceof Boolean)
{ left = (Boolean.valueOf((boolean) right).toString()); }***/
boolean strconcat = strict
? left instanceof String || right instanceof String
: left instanceof String && right instanceof String;
if (!strconcat) {
try {
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal)
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right))
// otherwise treat as integers
BigInteger l = toBigInteger(left);
BigInteger r = toBigInteger(right);
BigInteger result = l.add(r);
return narrowBigInteger(left, right, result);
} catch (java.lang.NumberFormatException nfe) {
if (left == null || right == null)
}
}
return toString(left).concat(toString(right));
}