Description
The compareTo() method of BigDecimal is not null safe due to which in the following code:
if (BigDecimal.ZERO.compareTo(shippingTotal) < 0 && BigDecimal.ZERO.compareTo(totalAllowance) < 0) { BigDecimal shippingAllowancePercent = storeShipMethod.getBigDecimal("allowancePercent") != null ? storeShipMethod.getBigDecimal("allowancePercent") : BigDecimal.ZERO; totalAllowance = totalAllowance.multiply(shippingAllowancePercent.divide(BigDecimal.valueOf(100))); shippingTotal = shippingTotal.subtract(totalAllowance); }
when totalAllowance value is null it throws null pointer exception which may be difficult to trace sometimes.
Valid null pointer checks should be there before using compareTo() if the variable may have a null value in any of the case.