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
e27afd1332
commit
fb9295ffb9
@ -356,8 +356,9 @@ public class XWPFRun implements ISDTContents, IRunElement{
|
|||||||
*/
|
*/
|
||||||
public UnderlinePatterns getUnderline() {
|
public UnderlinePatterns getUnderline() {
|
||||||
CTRPr pr = run.getRPr();
|
CTRPr pr = run.getRPr();
|
||||||
return (pr != null && pr.isSetU()) ? UnderlinePatterns.valueOf(pr
|
return (pr != null && pr.isSetU() && pr.getU().getVal() != null)
|
||||||
.getU().getVal().intValue()) : UnderlinePatterns.NONE;
|
? UnderlinePatterns.valueOf(pr.getU().getVal().intValue())
|
||||||
|
: UnderlinePatterns.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,8 +16,11 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xwpf.usermodel;
|
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.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -48,4 +51,30 @@ public class TestXWPFBugs {
|
|||||||
assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Arial");
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
test-data/document/57312.docx
Normal file
BIN
test-data/document/57312.docx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user