unexpected exception java.math.BigDecimal running on IBM WebSphere
Running Java app开发者_运维百科lication 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.
I would submit your issues to IBM Software Support. They don't charge per instance, it's unlimited amount of requests as long as you have a support agreement.
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));
}
}
Is policyFormTotal NULL? How about the result of formList.getFormPremiumAmt()? You never check those in this code block.
精彩评论