svn commit: r1814873 - /ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1814873 - /ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java

jleroux@apache.org
Author: jleroux
Date: Fri Nov 10 15:34:27 2017
New Revision: 1814873

URL: http://svn.apache.org/viewvc?rev=1814873&view=rev
Log:
Fixed: ShippingEvents.getShipGroupEstimate() method gives untraceable null
 pointer exception for BigDecimal comparison
(OFBIZ-9975)

The compareTo() method of BigDecimal is not null safe.
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.

Thanks: Aditya

Modified:
    ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java

Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java?rev=1814873&r1=1814872&r2=1814873&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java Fri Nov 10 15:34:27 2017
@@ -253,7 +253,7 @@ public class ShippingEvents {
 
         // Calculate the allowance price(Already included in Product's default/list price)
         // using shippingAllowance percent and deduct it from Actual Shipping Cost.
-        if (BigDecimal.ZERO.compareTo(shippingTotal) < 0 && BigDecimal.ZERO.compareTo(totalAllowance) < 0) {
+        if (BigDecimal.ZERO.compareTo(shippingTotal) < 0 && UtilValidate.isNotEmpty(totalAllowance) && 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);