]> source.dussan.org Git - poi.git/commitdiff
Bug 57312: Add check for null value of underline w:val
authorDominik Stadler <centic@apache.org>
Fri, 19 Dec 2014 14:29:50 +0000 (14:29 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 19 Dec 2014 14:29:50 +0000 (14:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1646729 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
test-data/document/57312.docx [new file with mode: 0644]

index 9234d18506a1a7caca06d2766eae2e71194978a0..d93e54f274798e8dece115cb62bd47453fa619e6 100644 (file)
@@ -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;
     }
 
     /**
index a40910df60cbf9177de78d5f9b50326ecc96c531..bded4e48c404439fdc3094c91ab9f77244751ae8 100644 (file)
 ==================================================================== */\r
 package org.apache.poi.xwpf.usermodel;\r
 \r
-import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.*;\r
 \r
+import java.io.IOException;\r
+\r
+import org.apache.poi.xwpf.XWPFTestDataSamples;\r
 import org.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange;\r
 import org.junit.Test;\r
 \r
@@ -48,4 +51,30 @@ public class TestXWPFBugs {
         assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Arial");\r
     }\r
 \r
+    \r
+    @Test\r
+    public void bug57312_NullPointException() throws IOException {\r
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("57312.docx");\r
+        assertNotNull(doc);\r
+        \r
+        for( IBodyElement bodyElement : doc.getBodyElements()){\r
+            BodyElementType elementType = bodyElement.getElementType();\r
+            \r
+            if(elementType == BodyElementType.PARAGRAPH) {\r
+                XWPFParagraph paragraph = (XWPFParagraph) bodyElement;\r
+                \r
+                for (IRunElement iRunElem : paragraph.getIRuns()){\r
+                    \r
+                    if (iRunElem instanceof XWPFRun){   \r
+                        XWPFRun runElement = (XWPFRun) iRunElem;\r
+                        \r
+                        UnderlinePatterns underline = runElement.getUnderline();\r
+                        assertNotNull(underline);\r
+                        \r
+                        //System.out.println("Found: " + underline + ": " + runElement.getText(0));\r
+                    }\r
+                }\r
+            } \r
+        }\r
+    }\r
 }\r
diff --git a/test-data/document/57312.docx b/test-data/document/57312.docx
new file mode 100644 (file)
index 0000000..3227597
Binary files /dev/null and b/test-data/document/57312.docx differ