Then open existing docx document as XWPFDocument, On onDocumentRead method initFootnotes method dublicate existing Footnotes in document. Here is a sample code with comments where there is a duplication: private void initFootnotes() throws XmlException, IOException { for(POIXMLDocumentPart p : getRelations()){ String relation = p.getPackageRelationship().getRelationshipType(); if (relation.equals(XWPFRelation.FOOTNOTE.getRelation())) { FootnotesDocument footnotesDocument = FootnotesDocument.Factory.parse(p.getPackagePart().getInputStream()); this.footnotes = (XWPFFootnotes)p; this.footnotes.onDocumentRead(); // THERE ARE WE ALREADY HAVE XWPFFootnotes WITH ALL DOCUMENT FOOTNOTES for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteList()) { footnotes.addFootnote(ctFtnEdn); // THERE ARE FOOTNOTES IS DUBLICATING } } else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){ EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream()); for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteList()) { endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn)); } } } }
Agreed. I noticed this while working on https://issues.apache.org/bugzilla/show_bug.cgi?id=54849. I've fixed the footnote duplication in 54849. Once that is commited, this issue will be fixed. Probably better practice (on my part) to have started a separate issue as you've done here. Thank you!
Created attachment 30465 [details] Simple testcase Testcase to prove that this issue was fixed in a patch for another issue.
Fixed in patch for 54849. Testcase attached. Thank you, Nick!
Thanks for this test Tim! Patch applied (with minor tweaks - the bug number for a test normally goes in the javadocs or method name) in r1494962.