From: Javen O'Neal Date: Sun, 11 Sep 2016 02:02:56 +0000 (+0000) Subject: bug 59958: Add cells on the fly to the evaluation sheet cache on cache miss; patch... X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6146860a5ea1be6851e90b37a042773a9a177dbf;p=poi.git bug 59958: Add cells on the fly to the evaluation sheet cache on cache miss; patch from Tomasz Stanczak git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760213 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java index c25dfb5d6c..7d9d0286f3 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java @@ -67,7 +67,28 @@ final class XSSFEvaluationSheet implements EvaluationSheet { } } - return _cellCache.get(new CellKey(rowIndex, columnIndex)); + final CellKey key = new CellKey(rowIndex, columnIndex); + EvaluationCell evalcell = _cellCache.get(key); + + // If cache is stale, update cache with this one cell + // This is a compromise between rebuilding the entire cache + // (which would quickly defeat the benefit of the cache) + // and not caching at all. + // See bug 59958: Add cells on the fly to the evaluation sheet cache on cache miss + if (evalcell == null) { + XSSFRow row = _xs.getRow(rowIndex); + if (row == null) { + return null; + } + XSSFCell cell = row.getCell(columnIndex); + if (cell == null) { + return null; + } + evalcell = new XSSFEvaluationCell(cell, this); + _cellCache.put(key, evalcell); + } + + return evalcell; } private static class CellKey {