You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2014/07/24 18:25:58 UTC

svn commit: r1613175 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Author: nick
Date: Thu Jul 24 16:25:58 2014
New Revision: 1613175

URL: http://svn.apache.org/r1613175
Log:
Correct HSSFOptimiser logic for the case where the to-keep style wasn't previously in use. Fixes #54443

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

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java?rev=1613175&r1=1613174&r2=1613175&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java Thu Jul 24 16:25:58 2014
@@ -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

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=1613175&r1=1613174&r2=1613175&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Thu Jul 24 16:25:58 2014
@@ -2679,4 +2679,27 @@ public final class TestBugs extends Base
         // 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);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org