poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1795254 - /poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
Date Tue, 16 May 2017 00:41:25 GMT
Author: onealj
Date: Tue May 16 00:41:25 2017
New Revision: 1795254

URL: http://svn.apache.org/viewvc?rev=1795254&view=rev
Log:
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

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java?rev=1795254&r1=1795253&r2=1795254&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java Tue May 16 00:41:25
2017
@@ -817,14 +817,30 @@ public class XWPFParagraph implements IB
      * @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;
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message