Bug 69042

Summary: Calling `insertNewParagraph` pointing to object in header leads to `ClassCastException`
Product: POI Reporter: aoellerer
Component: XWPFAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: major    
Priority: P2    
Version: 5.2.3-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

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
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).