Bug 62492

Summary: XSSFFontFormatting.setFontColor IndexOutOfBoundsException
Product: POI Reporter: martin19942010
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.17-FINAL   
Target Milestone: ---   
Hardware: All   
OS: All   

Description martin19942010 2018-06-26 23:40:55 UTC
I am trying to set the font of a conditional formatting However when I run

FontFormatting font1 = rule1.createFontFormatting();
font1.setFontColor(new XSSFColor(new java.awt.Color(198, 239, 206)));

I get an IndexOutOfBoundsException Shown below.

Exception in thread "main" java.lang.IndexOutOfBoundsException 
at org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl.setColorArray(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFFontFormatting.setFontColor(XSSFFontFormatting.java:125)

The code that breaks is 
    @Override
    public void setFontColor(Color color) {
        XSSFColor xcolor = XSSFColor.toXSSFColor(color);
        if (xcolor == null) {
            _font.getColorList().clear();
        } else {
            _font.setColorArray(0, xcolor.getCTColor());
        }
    }



This stack overflow post is the only place I can find the issue mentioned, however I dont beleive they ever submitted a bug report
https://stackoverflow.com/questions/45611870/can-not-set-font-color-in-conditional-formatting-cell-via-apache-poi
Comment 1 Greg Woolsey 2018-06-27 01:46:52 UTC
I can't find a bug associated with it, but this was fixed in POI trunk revision 1815086 [1] on Nov. 13, 2017.  It is in the current nightly builds, but there has not been a new release since then.  You could try a nightly build (suggestion recently was use one from a week or so ago).  The nightlies are for an upcoming 4.0 release, and have quite a few breaking API changes, mostly around converting int constant values to proper Enums.  Or you could apply the indicated change as a patch to a local build of 3.17.


[1] http://mail-archives.apache.org/mod_mbox/poi-commits/201711.mbox/%3C20171113114604.5B5253A01A6@svn01-us-west.apache.org%3E