Menu

#2284 Big Decimal exception calling setScale()

z_don't_use_3.5.4a
closed-accepted
Costing (71)
5
2010-04-26
2010-01-06
No

Big Decimal exception at completing Physical Inventory for products with cost=0

I reproduced it once with the following:
Create a Physical Inventory entry.
Create a line with a product which has costs=0.
Complete the Physical Inventory.

==> Error: Exception
java.lang.ArithmeticException: Rounding necessary (0): java.math.BigDecimal.divideAndRound(BigDecimal.java:1435)

The cause:
MCost.calculateAverageInv()
Statement newAmt = newAmt.setScale(as.getCostingPrecision());
(line 867)

The fix:
setScale() should be called with a second argument, specifying the required precision:
newAmt = newAmt.setScale(as.getCostingPrecision(),RoundingMode.HALF_UP);

This bug can actually happen always when evaluating costs for products with costs=0
I tried to reproduce it on testadempiere, but it doesn't seem to come to MCost.calculateAverageInv() .

Anyway, it is safer to call setScale() with a rounding mode.

Mario Calderon

Discussion

  • Carlos Ruiz

    Carlos Ruiz - 2010-04-10
    • assigned_to: nobody --> globalqss
    • status: open --> pending-accepted
     
  • SourceForge Robot

    • status: pending-accepted --> closed-accepted
     
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     

Log in to post a comment.