]> source.dussan.org Git - poi.git/commitdiff
Correct HSSFOptimiser logic for the case where the to-keep style wasn't previously...
authorNick Burch <nick@apache.org>
Thu, 24 Jul 2014 16:25:58 +0000 (16:25 +0000)
committerNick Burch <nick@apache.org>
Thu, 24 Jul 2014 16:25:58 +0000 (16:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1613175 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

index d05480dbf1c73e5f92c933481ce923fba55aaab0..238b89ed39537aa7539ed0ac477f68337e875207 100644 (file)
@@ -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
index 9421b5634800f98b8b09acb5711614142d3188bc..c2b4c67ba2fe6c6f89df715c7495cca9d262d6a7 100644 (file)
@@ -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);
+    }
 }