I have a strange behavior :
I have a method which get some data from a database
public void calculate(Run run, Map<String, Curve> epe) {
for (Entry<String, Curve> entry : epe.entrySet()) {
Entity ntt = leDAO.getById(entry.getKey(), run);
double lgd = leDAO.getLgd(ntt, run);
Curve dp = curveDAO.getDp(entry.getKey(), run);
String currency = leDAO.getCurrency(ntt, run);
Curve df = curveDAO.getDf(currency, run);
double val = 0.0;
for (int i = 0; i < pd.size(); i++) {
cva += entry.getValue().get(i) * df.get(i) * dp.get(i);
}
val *= lgd;
}
}
When debugging, halfway through the outer loop, it stops on this line, although I have no breakpoints set :
double lgd = leDAO.getLgd(ntt, run);
and then, it throws a NullPointerException, except I can't find what's null (leDAO, ntt and run are all set to something other than null). I can't step into the getLgd() method (I get in dispatchUncaughtException() from Thread.class if I do). The map has about 150 keys.
EDIT The getLgd() method :
public Double getLgd(Entity entity, Run run) throws HibernateException {
if (session == null) {
session = sessionFactory.openSession();
}
SQLQuery select = session.createSQLQuery(RECOVERY_SELECT);
select.setLong(0, run.getRunId());
select.setString(1, entity.getId());
BigDecimal result = (BigDecimal) select.uniqueResult();
Double lgd = null;
if (result != null) {
entity.setRr(result);
BigDecimal one = new BigDecimal(1);
BigDecimal normalLgd = one.subtract(result);
lgd = normalLgd.doubleValue();
}
return lgd;
}