From 7b15cc372e8f5564bb6e781f6a62fa2f0dae1a93 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Tue, 16 May 2017 00:41:25 +0000 Subject: [PATCH] github-53: fix NPE when iterating over paragraphs in certain *.docx files. Thanks to Praful Kumar Vaishnav! This closes #53. https://github.com/apache/poi/pull/53 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1795254 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xwpf/usermodel/XWPFParagraph.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java index 532a149671..64af4f4a6e 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -817,14 +817,30 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para * @return boolean - if page break is set */ public boolean isPageBreak() { - CTPPr ppr = getCTPPr(); - CTOnOff ctPageBreak = ppr.isSetPageBreakBefore() ? ppr - .getPageBreakBefore() : null; - if (ctPageBreak != null - && ctPageBreak.getVal().intValue() == STOnOff.INT_TRUE) { - return true; + final CTPPr ppr = getCTPPr(); + final CTOnOff ctPageBreak = ppr.isSetPageBreakBefore() ? ppr.getPageBreakBefore() : null; + if (ctPageBreak == null) { + return false; + } + return isTruelike(ctPageBreak.getVal(), false); + } + + private static boolean isTruelike(final STOnOff.Enum value, boolean defaultValue) { + if (value == null) { + return defaultValue; + } + switch (value.intValue()) { + case STOnOff.INT_TRUE: + case STOnOff.INT_X_1: + case STOnOff.INT_ON: + return true; + case STOnOff.INT_FALSE: + case STOnOff.INT_X_0: + case STOnOff.INT_OFF: + return false; + default: + return defaultValue; } - return false; } /**