From 531e4fee2e5501d32ac10d178d7e496608cdf2d9 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 14 Apr 2020 09:06:56 +0000 Subject: [PATCH] [bug-64348] partial fix for IndexOutOfBoundsException git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876487 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xwpf/model/XWPFHeaderFooterPolicy.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 3707ccc509..7cb5326291 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java +++ b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java @@ -425,8 +425,16 @@ public class XWPFHeaderFooterPolicy { */ private XWPFParagraph getWatermarkParagraph(String text, int idx) { CTP p = CTP.Factory.newInstance(); - byte[] rsidr = doc.getDocument().getBody().getPArray(0).getRsidR(); - byte[] rsidrdefault = doc.getDocument().getBody().getPArray(0).getRsidRDefault(); + CTBody ctBody = doc.getDocument().getBody(); + byte[] rsidr = null; + byte[] rsidrdefault = null; + if (ctBody.sizeOfPArray() == 0) { + // TODO generate rsidr and rsidrdefault + } else { + CTP ctp = ctBody.getPArray(0); + rsidr = ctp.getRsidR(); + rsidrdefault = ctp.getRsidRDefault(); + } p.setRsidP(rsidr); p.setRsidRDefault(rsidrdefault); CTPPr pPr = p.addNewPPr(); -- 2.39.5