Bug 63268

Summary: CellUtil setFont always creates new style
Product: POI Reporter: Oliver <oliver.flege>
Component: SS CommonAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   

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