Bug 63268 - CellUtil setFont always creates new style
Summary: CellUtil setFont always creates new style
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-18 10:40 UTC by Oliver
Modified: 2019-03-19 06:03 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver 2019-03-18 10:40:54 UTC
Setting the font of a cell using CellUtil.setFont(cell, font) always creates a new style in the workbook, regardless of whether the font is new or not, and may therefore lead to "IllegalStateException: The maximum number of cell styles was exceeded". 
Problem seems to be that the private putAll method in CellUtil stores a Short value for the font in the map, whereas getFormatProperties(CellStyle style) uses an Int, so that the "if (wbStyleMap.equals(values))" call in setCellStyleProperties will always return false. 

Steps to reproduce:

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFCell c = wb.createSheet().createRow(1).createCell(1);
        HSSFFont f = wb.createFont();

        CellUtil.setFont(c, f);
        int num1 = wb.getNumCellStyles();

        CellUtil.setFont(c, f);
        int num2 = wb.getNumCellStyles();

        System.out.println(num1 == num2); // should print true, prints false
Comment 1 PJ Fanning 2019-03-19 06:03:04 UTC
Fix applied with https://svn.apache.org/viewvc?view=revision&revision=1855806