*/
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;
}
/**
==================================================================== */\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
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