mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
1939a50de8
commit
1b435fa805
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue