Bug 68703 - IllegalArgumentException: Unexpected color choice CTFontCollectionImpl when reading font color for a table cell
Summary: IllegalArgumentException: Unexpected color choice CTFontCollectionImpl when r...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-04 07:04 UTC by Henry Iguaro
Modified: 2024-03-06 08:49 UTC (History)
0 users



Attachments
Zip file containing a Maven project that reproduces the issue (55.26 KB, application/zip)
2024-03-04 07:04 UTC, Henry Iguaro
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Henry Iguaro 2024-03-04 07:04:24 UTC
Created attachment 39609 [details]
Zip file containing a Maven project that reproduces the issue

Affected Version: 5.2.5 (5.2.4 possibly affected as well)

Issue:
When parsing some PowerPoint files with tables in Apache POI version 5.2.5 (and possibly 5.2.4), attempting to retrieve the font color for text runs within the table cell triggers the following exception:

```
Exception in thread "main" java.lang.IllegalArgumentException: Unexpected color choice: class org.openxmlformats.schemas.drawingml.x2006.main.impl.CTFontCollectionImpl
	at org.apache.poi.xslf.usermodel.XSLFColor.toColor(XSLFColor.java:161)
	at org.apache.poi.xslf.usermodel.XSLFColor.<init>(XSLFColor.java:66)
	at org.apache.poi.xslf.usermodel.XSLFTableCell$XSLFCellTextRun.getFontColor(XSLFTableCell.java:755)
	at com.example.Main.main(Main.java:21)
```

Steps to Reproduce:
1. Download the attached zip file containing a Maven project.
2. Unzip the folder and navigate to its directory using the command line.
3. Run `mvn install` followed by `mvn exec:java`.
4. Observe the `IllegalArgumentException` that is thrown during execution.

We suspect that the commit causing this issue is https://github.com/apache/poi/commit/624f83431065e1a7613f1f044f1820c27e504266#diff-f80c56131e376f24468d40928f5717820b38f1ebea9d16147b870763f8b682c7R78
Comment 1 PJ Fanning 2024-03-04 12:47:25 UTC
Looks like you are right about that newTextRun change. The XSLFTableCell class overrides this method and returns an XSLFCellTextRun instead of a XSLFTextRun. I will revert that change.
Comment 2 PJ Fanning 2024-03-04 12:49:20 UTC
added r1916105
Comment 3 PJ Fanning 2024-03-04 14:02:52 UTC
reverted with r1916106 - I will have to come back to this.

With POI these days, it seems almost impossible to change code to suit one user without breaking the code for another.
Comment 4 PJ Fanning 2024-03-04 14:59:17 UTC
trying again with r1916108