This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository lima. See http://git.chorem.org/lima.git commit 4c4e28c6a551637044f43ba17561e50b7ead5080 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Feb 27 10:38:20 2015 +0100 improve code (limit scope of try - catch block) + add comment for NPE --- .../ui/celleditor/BigDecimalTableCellEditor.java | 47 +++++++++++++--------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java b/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java index 121c695..a2451a4 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java @@ -71,30 +71,37 @@ public class BigDecimalTableCellEditor extends StringTableCellEditor { @Override public BigDecimal getCellEditorValue() { BigDecimal cellEditorValue; - try { - String stringValue = super.getCellEditorValue().toString(); - if (StringUtils.isBlank(stringValue)) { - stringValue = "0"; - } - stringValue=stringValue.replaceAll(",","."); - - int pointIndex = stringValue.indexOf("."); - if (pointIndex != -1) { - LimaSwingConfig config = LimaSwingApplicationContext.getContext().getConfig(); - String actualDecimals = stringValue.substring(pointIndex, stringValue.length()-1); - if (config.getScale() > actualDecimals.length()) { - cellEditorValue = new BigDecimal(stringValue); - } else { - int decimalLength = config.getScale() + pointIndex + 1; - String roundedStringValue = stringValue.substring(0, pointIndex) + - stringValue.substring(pointIndex, decimalLength); - cellEditorValue = new BigDecimal(roundedStringValue); - } + + String stringValue = super.getCellEditorValue().toString(); + if (StringUtils.isBlank(stringValue)) { + stringValue = "0"; + } + stringValue = stringValue.replaceAll(",", "."); + + String valueToConvert; + + int pointIndex = stringValue.indexOf("."); + if (pointIndex != -1) { + LimaSwingConfig config = LimaSwingApplicationContext.getContext().getConfig(); + String actualDecimals = stringValue.substring(pointIndex, stringValue.length() - 1); + if (config.getScale() > actualDecimals.length()) { + valueToConvert = stringValue; } else { - cellEditorValue = new BigDecimal(stringValue); + int decimalLength = config.getScale() + pointIndex + 1; + String roundedStringValue = stringValue.substring(0, pointIndex) + + stringValue.substring(pointIndex, decimalLength); + valueToConvert = roundedStringValue; } + } else { + valueToConvert = stringValue; + } + try { + + cellEditorValue = new BigDecimal(valueToConvert); + } catch (NumberFormatException e) { // it cancel current cell value + // tchemit-2015-02-27 Can't have a null value (NPE in DebitColim.setValueAt) cellEditorValue = BigDecimal.ZERO; } return cellEditorValue; -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.