Bug 50299 - NullPointer Exception in XSSFCellStyle.getFillForegroundXSSFColor()
Summary: NullPointer Exception in XSSFCellStyle.getFillForegroundXSSFColor()
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.7-FINAL
Hardware: PC All
: P2 major with 3 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-19 04:12 UTC by akira yokoi
Modified: 2011-02-28 10:15 UTC (History)
0 users



Attachments
error xlsx file (34.41 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2010-11-19 09:14 UTC, akira yokoi
Details
error java code (1.78 KB, application/octet-stream)
2010-11-19 09:15 UTC, akira yokoi
Details
Patch (1.07 KB, text/plain)
2011-02-16 07:09 UTC, andrei
Details
XSSFColor patch (2.51 KB, application/octet-stream)
2011-02-21 13:14 UTC, andrei
Details

Note You need to log in before you can comment on or make changes to this bug.
Description akira yokoi 2010-11-19 04:12:34 UTC
java.lang.NullPointerException
	at org.apache.poi.xssf.model.ThemesTable.getThemeColor(ThemesTable.java:54)
	at org.apache.poi.xssf.usermodel.XSSFCellStyle.extractColorFromTheme(XSSFCellStyle.java:1454)
	at org.apache.poi.xssf.usermodel.XSSFCellStyle.getFillForegroundXSSFColor(XSSFCellStyle.java:481)
	at org.bbreak.excella.reports.ReportsTestUtil.getCellStyleString(ReportsTestUtil.java:593)
Comment 1 Yegor Kozlov 2010-11-19 08:37:47 UTC
Please post the complete Java code to reproduce the problem. If your code
requires an .xls template then upload it too.

Yegor
Comment 2 akira yokoi 2010-11-19 09:14:41 UTC
Created attachment 26317 [details]
error xlsx file
Comment 3 akira yokoi 2010-11-19 09:15:16 UTC
Created attachment 26318 [details]
error java code
Comment 4 andrei 2011-02-15 09:43:25 UTC
XSSFCellStyle.getFillForegroundXSSFColor() throws NPE when the cell background color is set from two first columns of the theme color palette (ie tints of white and black colors). СTColor.getSrgbClr() in getThemeColor(int) method returns null for these colors. It's necessary return CTColor.getSysClr().getLastClr() in such cases.
Comment 5 Nick Burch 2011-02-15 11:49:27 UTC
Any chance you could work up a patch + unit test based on your findings?
Comment 6 andrei 2011-02-16 07:09:56 UTC
Created attachment 26665 [details]
Patch
Comment 7 Nick Burch 2011-02-18 11:44:43 UTC
Thanks for the patch and test

I've applied the patch to svn in r1072053, and added the unit test too.

However, one thing I'm not sure on is the values coming back. I added one extra bit to the test, which was to check the whites and blacks in the first sheet. They're coming back apparent the same though...

Any chance you could take a look at the test in xssf.usermodel.TestBugs and see if you can spot why we're not seeing different values?
Comment 8 andrei 2011-02-21 13:00:44 UTC
White and black colors are theme colors, not indexed, and getFillForegroundColor() method returns 0 (index) (as for all theme colors). And getFillBackgroundColor() returns 64 (default AUTOMATIC color index) for theme colors. So, it's not a bug.
Comment 9 andrei 2011-02-21 13:13:30 UTC
I found another problem - instead of pure white, Excel returns the black, and for black - white.

See fix patch in attachment.

I also removed the Alpha for indexed colors from getRgb() as unnecessary (ctColor.getRgb() returns rgb only).
Comment 10 andrei 2011-02-21 13:14:48 UTC
Created attachment 26688 [details]
XSSFColor patch
Comment 11 Nick Burch 2011-02-25 16:22:12 UTC
One snag - ctColor.getRGB() almost always returns 4 values, including the Alpha. It's only theme colours where you only get the 3, and in most cases one your construct yourself

After trying a few things, the safest thing seemed to be to offer two methods, one which returns the RGB and one that returns ARGB (assuming that if it wasn't given, then the alpha if 0xFF). Hopefully that does the right thing?
Comment 12 andrei 2011-02-28 10:15:09 UTC
I think this is a good solution