aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2014-07-24 16:25:58 +0000
committerNick Burch <nick@apache.org>2014-07-24 16:25:58 +0000
commitc76f1676030c8de7d08538527b717893dd3c6ddc (patch)
treeb983155a665e6aca3556eba5c843d2bf81ab41e5 /src
parenteddef8c7f8cb97a8043c2e92dd578de6ddd5238f (diff)
downloadpoi-c76f1676030c8de7d08538527b717893dd3c6ddc.tar.gz
poi-c76f1676030c8de7d08538527b717893dd3c6ddc.zip
Correct HSSFOptimiser logic for the case where the to-keep style wasn't previously in use. Fixes #54443
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1613175 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java23
2 files changed, 27 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java b/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java
index d05480dbf1..238b89ed39 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java
@@ -210,6 +210,10 @@ public class HSSFOptimiser {
newPos[i] = (short)earlierDuplicate;
zapRecords[i] = true;
}
+ // If we got a duplicate, mark the one we're keeping as used
+ if(earlierDuplicate != -1) {
+ isUsed[earlierDuplicate] = true;
+ }
}
// Loop over all the cells in the file, and identify any user defined
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index 9421b56348..c2b4c67ba2 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -2679,4 +2679,27 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Try to evaluate everything
eval.evaluateAll();
}
+
+ /**
+ * ClassCastException in HSSFOptimiser - StyleRecord cannot be cast to
+ * ExtendedFormatRecord when removing un-used styles
+ */
+ @Test
+ public void bug54443() throws Exception {
+ HSSFWorkbook workbook = new HSSFWorkbook( );
+ HSSFCellStyle style = workbook.createCellStyle();
+ HSSFCellStyle newStyle = workbook.createCellStyle();
+
+ HSSFSheet mySheet = workbook.createSheet();
+ HSSFRow row = mySheet.createRow(0);
+ HSSFCell cell = row.createCell(0);
+
+ // Use style
+ cell.setCellStyle(style);
+ // Switch to newStyle, style is now un-used
+ cell.setCellStyle(newStyle);
+
+ // Optimise
+ HSSFOptimiser.optimiseCellStyles(workbook);
+ }
}