diff --git a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java index 8ff59713a..682b1cfd4 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java +++ b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java @@ -29,6 +29,7 @@ import org.apache.poi.xwpf.usermodel.XWPFHeader; import org.apache.poi.xwpf.usermodel.XWPFHeaderFooter; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFRelation; +import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtrRef; @@ -115,8 +116,14 @@ public class XWPFHeaderFooterPolicy { if (relatedPart != null && relatedPart instanceof XWPFHeader) { hdr = (XWPFHeader) relatedPart; } - // Assign it - Enum type = ref.getType(); + // Assign it; treat invalid options as "default" POI-60293 + Enum type; + try { + type = ref.getType(); + } catch (XmlValueOutOfRangeException e) { + type = STHdrFtr.DEFAULT; + } + assignHeader(hdr, type); } for (int i = 0; i < sectPr.sizeOfFooterReferenceArray(); i++) { @@ -127,8 +134,13 @@ public class XWPFHeaderFooterPolicy { if (relatedPart != null && relatedPart instanceof XWPFFooter) { ftr = (XWPFFooter) relatedPart; } - // Assign it - Enum type = ref.getType(); + // Assign it; treat invalid options as "default" POI-60293 + Enum type; + try { + type = ref.getType(); + } catch (XmlValueOutOfRangeException e) { + type = STHdrFtr.DEFAULT; + } assignFooter(ftr, type); } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java index 371c9da06..fbb24f506 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java @@ -220,4 +220,11 @@ public final class TestXWPFHeader { public void testGetPictureDataById() { // TODO } + + @Test + public void bug60293() throws Exception { + //test handling of non-standard header/footer options + XWPFDocument xwpf = XWPFTestDataSamples.openSampleDocument("60293.docx"); + assertEquals(3, xwpf.getHeaderList().size()); + } } diff --git a/test-data/document/60293.docx b/test-data/document/60293.docx new file mode 100644 index 000000000..02dcabc9c Binary files /dev/null and b/test-data/document/60293.docx differ