Bug 69042 - Calling `insertNewParagraph` pointing to object in header leads to `ClassCastException`
Summary: Calling `insertNewParagraph` pointing to object in header leads to `ClassCast...
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 5.2.3-FINAL
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-23 15:31 UTC by aoellerer
Modified: 2024-05-28 11:34 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description aoellerer 2024-05-23 15:31:09 UTC
When trying to insert an object into a document via `XWPFDocument#insertNewParagraph(XmlCursor cursor)`, where the cursor points to something in the header/footer, a `ClassCastException` is thrown.

The reason for this is in `insertIntoParentElement(IBodyElement iBodyElement, Deque<XmlObject> path)`, where I assumed that the element can only be nested in a table, when in reality it can also be in a header or footer.
Comment 1 aoellerer 2024-05-27 09:08:17 UTC
https://github.com/apache/poi/pull/640
Comment 2 aoellerer 2024-05-28 11:34:02 UTC
I did some more work around this problem and discovered that the problem might actually lie somewhere else, as XWPFDocument.insertNewParagraph(XmlCursor) should not be invoked if the parent object is actually a XWPFHeaderFooter, instead we should use XWPFHeaderFooter.insertNewParagraph(XmlCursor).