Program: 58810
Project: 58810
Buggy source:
@Transactional public void insertKMExpenses(ActionRequest request,ActionResponse response){
  User user=AuthUtils.getUser();
  ProjectTask projectTask=Beans.get(ProjectTaskRepository.class).find(new Long(request.getData().get("String_Node_Str").toString()));
  if (user != null) {
    Expense expense=Beans.get(ExpenseRepository.class).all().filter("String_Node_Str",user.getId()).order("String_Node_Str").fetchOne();
    if (expense == null) {
      expense=new Expense();
      expense.setUser(user);
      expense.setCompany(user.getActiveCompany());
      expense.setStatusSelect(TimesheetRepository.STATUS_DRAFT);
    }
    KilometricAllowance kmAllowance=new KilometricAllowance();
    kmAllowance.setDistance(new BigDecimal(request.getData().get("String_Node_Str").toString()));
    kmAllowance.setCityFrom(request.getData().get("String_Node_Str").toString());
    kmAllowance.setCityTo(request.getData().get("String_Node_Str").toString());
    kmAllowance.setProjectTask(projectTask);
    kmAllowance.setTypeSelect(new Integer(request.getData().get("String_Node_Str").toString()));
    kmAllowance.setToInvoice(new Boolean(request.getData().get("String_Node_Str").toString()));
    kmAllowance.setReason(request.getData().get("String_Node_Str").toString());
    if (user.getEmployee() != null && user.getEmployee().getFiscalPower() != null) {
      kmAllowance.setFiscalPower(user.getEmployee().getFiscalPower());
      KilometricAllowanceRate kilometricAllowanceRate=Beans.get(KilometricAllowanceRateRepository.class).findByVehicleFiscalPower(user.getEmployee().getFiscalPower());
      if (kilometricAllowanceRate != null) {
        BigDecimal rate=kilometricAllowanceRate.getRate();
        if (rate != null) {
          kmAllowance.setInTaxTotal(rate.multiply(kmAllowance.getDistance()));
        }
      }
    }
    expense.addKilometricAllowanceListItem(kmAllowance);
    Beans.get(ExpenseRepository.class).save(expense);
  }
}

Fixed version (ground truth):
@Transactional public void insertKMExpenses(ActionRequest request,ActionResponse response){
  User user=AuthUtils.getUser();
  if (user != null) {
    Expense expense=Beans.get(ExpenseRepository.class).all().filter("String_Node_Str",user.getId()).order("String_Node_Str").fetchOne();
    if (expense == null) {
      expense=new Expense();
      expense.setUser(user);
      expense.setCompany(user.getActiveCompany());
      expense.setStatusSelect(TimesheetRepository.STATUS_DRAFT);
    }
    KilometricAllowance kmAllowance=new KilometricAllowance();
    kmAllowance.setDistance(new BigDecimal(request.getData().get("String_Node_Str").toString()));
    kmAllowance.setCityFrom(request.getData().get("String_Node_Str").toString());
    kmAllowance.setCityTo(request.getData().get("String_Node_Str").toString());
    kmAllowance.setTypeSelect(new Integer(request.getData().get("String_Node_Str").toString()));
    kmAllowance.setReason(request.getData().get("String_Node_Str").toString());
    kmAllowance.setDate(new LocalDate(request.getData().get("String_Node_Str").toString()));
    if (user.getEmployee() != null && user.getEmployee().getFiscalPower() != null) {
      kmAllowance.setFiscalPower(user.getEmployee().getFiscalPower());
      KilometricAllowanceRate kilometricAllowanceRate=Beans.get(KilometricAllowanceRateRepository.class).findByVehicleFiscalPower(user.getEmployee().getFiscalPower());
      if (kilometricAllowanceRate != null) {
        BigDecimal rate=kilometricAllowanceRate.getRate();
        if (rate != null) {
          kmAllowance.setInTaxTotal(rate.multiply(kmAllowance.getDistance()));
        }
      }
    }
    expense.addKilometricAllowanceListItem(kmAllowance);
    Beans.get(ExpenseRepository.class).save(expense);
  }
}