Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
No replies
SystemAdmin
SystemAdmin
102 Posts
ACCEPTED ANSWER

Pinned topic BigDecimal.toString2() NullPointerException

‏2012-12-11T19:36:35Z |
Hi,
My application suddenly occur this.
Every JavaBean's property need to format, such as money、rate etc.. throw NullPointException, when I use Hibernate query.
Then I restart the application Server, everything is fine.
Who can tell me why?

these are stacktrace:

Caused by: org.hibernate.PropertyAccessException: Exception occurred inside getter of com.leadmind.common.fbo.hibernate.bbsp.bd.sale.SaleApplyInfo.buybackRate
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:148)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValues(AbstractEntityTuplizer.java:256)
at org.hibernate.tuple.entity.PojoEntityTuplizer.getPropertyValues(PojoEntityTuplizer.java:209)
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValues(AbstractEntityPersister.java:3581)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:167)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:930)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
... 119 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor4335.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:599)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 132 more
Caused by: java.lang.NullPointerException
at java.math.BigDecimal.toString2(BigDecimal.java:7652)
at java.math.BigDecimal.toString(BigDecimal.java:7180)
at java.math.BigDecimal.doubleValue(BigDecimal.java:4830)
at com.leadmind.common.systools.MathScaleUtil.round(MathScaleUtil.java:213)
at com.leadmind.common.systools.MathScaleUtil.round(MathScaleUtil.java:272)
at com.leadmind.common.systools.MathScaleUtil.round(MathScaleUtil.java:256)
at com.leadmind.common.systools.MoneyUtils.formate(MoneyUtils.java:226)
at com.leadmind.common.systools.MoneyUtils.formateRate(MoneyUtils.java:269)
at com.leadmind.common.fbo.hibernate.bbsp.bd.sale.SaleApplyInfo.getBuybackRate(SaleApplyInfo.java:564)

/MathScaleUtil/
public static double round(double v, int scale, int round_mode) {
if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b = new BigDecimal(Double.toString(v));
return b.setScale(scale, round_mode).doubleValue();
}

public static String round(String v, int scale) {
return round(v, scale, BigDecimal.ROUND_HALF_UP);
}

public static String round(String v, int scale, int round_mode) {
if (v == null) {
return null;
}

if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b = new BigDecimal(v);
return b.setScale(scale, round_mode).toString();
}

public static Double round(Double v, int scale) {
return round(v, scale, BigDecimal.ROUND_HALF_UP);
}

public static Double round(Double v, int scale, int round_mode) {
if (v == null) {
return null;
}

return new Double(round(v.doubleValue(), scale, round_mode));
}