起因
上周客户在导入数据的时候发现导入的表格(含有计算公式)结果的值有些为空,查后台日志发现是导入失败,Exception: IllegalStateException: value changed。
猜测
将表格拿到开发环境测试成功复现问题,打断点查看 StackTrace 找到如下代码:
public class EvaluationCache {
//...........
public PlainValueCellCacheEntry getPlainValueEntry(int bookIndex, int sheetIndex,
int rowIndex, int columnIndex, ValueEval value) {
Loc loc = new Loc(bookIndex, sheetIndex, rowIndex, columnIndex);
PlainValueCellCacheEntry result = _plainCellCache.get(loc);
if (result == null) {
result = new PlainValueCellCacheEntry(value);
_plainCellCache.put(loc, result);
if (_evaluationListener != null) {
_evaluationListener.onReadPlainValue(sheetIndex, rowIndex, columnIndex, result);
}
} else {
// TODO - if we are confident that this sanity check is not required, we can remove 'value' from plain value cache entry
if (!areValuesEqual(result.getValue(), value)) {
throw new IllegalStateException("value changed"); //在这里报错!
}
if (_evaluationListener != null) {
_evaluationListener.onCacheHit(sheetIndex, rowIndex, columnIndex, value);
}
}
return result;
}
//................
}
大约 2 分钟