From 6f36fed29f74334071367c7ff477d89444014d79 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Sun, 11 Sep 2016 02:02:56 +0000 Subject: [PATCH] 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 --- .../xssf/usermodel/XSSFEvaluationSheet.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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 { -- 2.39.5