diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandlerUtils.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandlerUtils.java index c396f98351c..1e794ed347a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandlerUtils.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/ImportHandlerUtils.java @@ -63,8 +63,13 @@ public static Long readAsLong(int colIndex, Row row) { FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { if(eval!=null) { - CellValue val = eval.evaluate(c); - return ((Double) val.getNumberValue()).longValue(); + CellValue val = null; + try { + val = eval.evaluate(c); + } catch (NullPointerException npe) { + return null; + } + return ((Double)val.getNumberValue()).longValue(); } } else if (c.getCellType()==Cell.CELL_TYPE_NUMERIC){ @@ -85,7 +90,13 @@ public static String readAsString(int colIndex, Row row) { FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { if (eval!=null) { - CellValue val = eval.evaluate(c); + CellValue val = null; + try { + val = eval.evaluate(c); + } catch(NullPointerException npe) { + return null; + } + String res = trimEmptyDecimalPortion(val.getStringValue()); if (res!=null) { if (!res.equals("")) { @@ -136,7 +147,12 @@ public static Boolean readAsBoolean(int colIndex, Row row) { FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { if(eval!=null) { - CellValue val = eval.evaluate(c); + CellValue val = null; + try { + val = eval.evaluate(c); + } catch (NullPointerException npe) { + return false; + } return val.getBooleanValue(); } return false; @@ -158,8 +174,13 @@ public static Integer readAsInt(int colIndex, Row row) { FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { if(eval!=null) { - CellValue val = eval.evaluate(c); - return ((Double) val.getNumberValue()).intValue(); + CellValue val = null; + try { + val = eval.evaluate(c); + } catch (NullPointerException npe) { + return null; + } + return ((Double)val.getNumberValue()).intValue(); } return null; }else if (c.getCellType()==Cell.CELL_TYPE_NUMERIC) { @@ -176,7 +197,12 @@ public static Double readAsDouble(int colIndex, Row row) { FormulaEvaluator eval = row.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); if(c.getCellType() == Cell.CELL_TYPE_FORMULA) { if (eval!=null) { - CellValue val = eval.evaluate(c); + CellValue val = null; + try { + val = eval.evaluate(c); + } catch (NullPointerException npe) { + return 0.0; + } return val.getNumberValue(); }else { return 0.0;