diff options
author | Dominik Stadler <centic@apache.org> | 2014-12-19 14:29:50 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2014-12-19 14:29:50 +0000 |
commit | 1b435fa80559af28aa3caa4060a2044fcbbe8022 (patch) | |
tree | 5b2b2c95ba459c2c6b1b34521af0ba615bc312fe | |
parent | 1939a50de8428e9a76b268d8469ba4994a3c0f2f (diff) | |
download | poi-1b435fa80559af28aa3caa4060a2044fcbbe8022.tar.gz poi-1b435fa80559af28aa3caa4060a2044fcbbe8022.zip |
Bug 57312: Add check for null value of underline w:val
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1646729 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java | 5 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java | 31 | ||||
-rw-r--r-- | test-data/document/57312.docx | bin | 0 -> 21702 bytes |
3 files changed, 33 insertions, 3 deletions
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java index 9234d18506..d93e54f274 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java @@ -356,8 +356,9 @@ public class XWPFRun implements ISDTContents, IRunElement{ */ public UnderlinePatterns getUnderline() { CTRPr pr = run.getRPr(); - return (pr != null && pr.isSetU()) ? UnderlinePatterns.valueOf(pr - .getU().getVal().intValue()) : UnderlinePatterns.NONE; + return (pr != null && pr.isSetU() && pr.getU().getVal() != null) + ? UnderlinePatterns.valueOf(pr.getU().getVal().intValue()) + : UnderlinePatterns.NONE; } /** diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java index a40910df60..bded4e48c4 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java @@ -16,8 +16,11 @@ ==================================================================== */
package org.apache.poi.xwpf.usermodel;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
+import java.io.IOException;
+
+import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange;
import org.junit.Test;
@@ -48,4 +51,30 @@ public class TestXWPFBugs { assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Arial");
}
+
+ @Test
+ public void bug57312_NullPointException() throws IOException {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("57312.docx");
+ assertNotNull(doc);
+
+ for( IBodyElement bodyElement : doc.getBodyElements()){
+ BodyElementType elementType = bodyElement.getElementType();
+
+ if(elementType == BodyElementType.PARAGRAPH) {
+ XWPFParagraph paragraph = (XWPFParagraph) bodyElement;
+
+ for (IRunElement iRunElem : paragraph.getIRuns()){
+
+ if (iRunElem instanceof XWPFRun){
+ XWPFRun runElement = (XWPFRun) iRunElem;
+
+ UnderlinePatterns underline = runElement.getUnderline();
+ assertNotNull(underline);
+
+ //System.out.println("Found: " + underline + ": " + runElement.getText(0));
+ }
+ }
+ }
+ }
+ }
}
diff --git a/test-data/document/57312.docx b/test-data/document/57312.docx Binary files differnew file mode 100644 index 0000000000..3227597391 --- /dev/null +++ b/test-data/document/57312.docx |