Bug 55066 - Then open XWPFDocument onDocumentRead method dublicate existing Footnotes.
Summary: Then open XWPFDocument onDocumentRead method dublicate existing Footnotes.
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 3.9-FINAL
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2013-06-06 07:17 UTC by Andzej Monkevic
Modified: 2013-06-20 12:51 UTC (History)
0 users

Simple testcase (683 bytes, patch)
2013-06-20 00:04 UTC, Tim Allison
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andzej Monkevic 2013-06-06 07:17:42 UTC
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));
Comment 1 Tim Allison 2013-06-06 12:27:58 UTC
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!
Comment 2 Tim Allison 2013-06-20 00:04:34 UTC
Created attachment 30465 [details]
Simple testcase

Testcase to prove that this issue was fixed in a patch for another issue.
Comment 3 Tim Allison 2013-06-20 00:05:40 UTC
Fixed in patch for 54849.  Testcase attached.  Thank you, Nick!
Comment 4 Nick Burch 2013-06-20 12:51:38 UTC
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.