Running Java application on IBM WebSphere caused such exception:
Caused by: java.lang.NullPointerException
at java.math.BigDecimal.add2DFP(BigDecimal.java:1946)
at java.math.BigDecimal.add(BigDecimal.java:1881)
at com.somepackage.components.view.PremiumSummaryViewModel.setPremiums(PremiumSummaryViewModel.java:101)
Null check is done. As I reviewed java.math.BigDecimal class has no such method add2DFP and does not call one either. Maybe it's specific to IBM's JDK.
Any comment on this would be appreciated.
Providing code regarding to exception
BigDecimal annualPremiumAmt = nwtPremium != null && nwtPremium.getAnnualAmt() != null ? nwtPremium.getAnnualAmt() : BigDecimal.ZERO;
if (nwtPremium != null) {
BigDecimal formPremiumAmt = nwtPremium.getAnnualAmt();
if (formPremiumAmt != null) {
policyFormTotal = policyFormTotal.add(annualPremiumAmt); //Bigdecimal
formList.setFormPremiumAmt(formList.getFormPremiumAmt().add(annualPremiumAmt)); //101 line
}
}
Instance is running on IBM JDK 1.6.
Fixed:
Actually this whole expression is inside the loop that I thought was unnecessary to mention. I have moved declaration of BigDecimal annualPremiumAmt before the loop and reorganized code:
BigDecimal annualPremiumAmt;
for(...) {
if (nwtPremium) {
annualPremiumAmt = nwtPremium.getAnnualAmt() != null ? nwtPremium.getAnnualAmt() : BigDecimal.ZERO;
policyFormTotal = policyFormTotal.add(annualPremiumAmt);
formList.setFormPremiumAmt(formList.getFormPremiumAmt().add(annualPremiumAmt));
}
}