diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java index 0be1a2f74b..083ede0968 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java @@ -72,8 +72,7 @@ public abstract class XWPFAbstractFootnoteEndnote implements Iterable(); // parse the document with cursor and add // the XmlObject to its lists - XmlCursor cursor = headerFooter.newCursor(); - try { + try (XmlCursor cursor = headerFooter.newCursor()) { cursor.selectPath("./*"); while (cursor.toNextSelection()) { XmlObject o = cursor.getObject(); @@ -542,8 +517,6 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo bodyElements.add(t); } } - } finally { - cursor.dispose(); } }