Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.7.10
-
Fix Version/s: 2.0-beta-3
-
Component/s: None
-
Labels:
-
Testcase included:yes
-
Number of attachments :
Description
Using the add operator on null BigDecimal objects concatenates them as Strings
@Test
void testNullBigDecimalAddOperator() {
BigDecimal a = null
BigDecimal b = null
assert null == a+b
}
Assertion failed:
assert null == a+b
| |||
| ||null
| |nullnull
| null
false
I would expect a NullPointer would be thrown as the divide operator behaves.
@Test(expected=NullPointerException)
void testNullBigDecimalDivOperator() {
BigDecimal a = null
BigDecimal b = null
assert null == a/b
}
java.lang.NullPointerException: Cannot invoke method div() on null object
at the time of invocation of the plus method it does not matter what type you statically declared for the types. We always take the runtime types and since null has none really, we take NullObject instead. So this issue is not about BigDecimal#plus, but about NullObject#plus. This method now basically does: "null"+b leading to the "nullnull" you have observed.
We can of course do a special case for null+null, but you actually want a NPE for the cases of any of the operands null, or not? That would break code.
So I kind of tend to close this issue as "Won't Fix".