mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
eddef8c7f8
commit
c76f167603
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue