Selaa lähdekoodia

Fix ArrayIndexOutOfBoundsException if XWPFRun does not set style

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1889259 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_1_0
Sayi 3 vuotta sitten
vanhempi
commit
90f228cabb

+ 2
- 7
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java Näytä tiedosto

@@ -1248,16 +1248,11 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
*/
public String getStyle() {
CTRPr pr = getCTR().getRPr();
if (pr == null) {
if (pr == null || pr.sizeOfRStyleArray() <= 0) {
return "";
}

CTString style = pr.getRStyleArray(0);
if (style == null) {
return "";
}

return style.getVal();
return null == style ? "" : style.getVal();
}



+ 11
- 0
poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Näytä tiedosto

@@ -788,6 +788,17 @@ class TestXWPFRun {
document.close();
}

@Test
void testGetEmptyStyle() throws IOException {
XWPFDocument document = new XWPFDocument();
final XWPFRun run = document.createParagraph().createRun();
assertEquals("", run.getStyle());

run.getCTR().addNewRPr();
assertEquals("", run.getStyle());
document.close();
}

@Test
void testGetDepthWidth() throws IOException, InvalidFormatException {
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx")) {

Loading…
Peruuta
Tallenna