POI-60341: handle missing sdtpr in an sdtbody

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1768048 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tim Allison 2016-11-04 15:06:17 +00:00
parent 7c9754a08d
commit d769a03fda
2 changed files with 39 additions and 25 deletions

View File

@ -33,7 +33,10 @@ public abstract class AbstractXWPFSDT implements ISDTContents {
private final IBody part;
public AbstractXWPFSDT(CTSdtPr pr, IBody part) {
if (pr == null) {
title = "";
tag = "";
} else {
CTString[] aliases = pr.getAliasArray();
if (aliases != null && aliases.length > 0) {
title = aliases[0].getVal();
@ -46,6 +49,7 @@ public abstract class AbstractXWPFSDT implements ISDTContents {
} else {
tag = "";
}
}
this.part = part;
}

View File

@ -17,6 +17,7 @@
package org.apache.poi.xwpf.usermodel;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -131,6 +132,15 @@ public final class TestXWPFSDT extends TestCase {
}
}
public void test60341() throws IOException {
//handle sdtbody without an sdtpr
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug60341.docx");
List<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
assertEquals(1, sdts.size());
assertEquals("", sdts.get(0).getTag());
assertEquals("", sdts.get(0).getTitle());
}
private List<AbstractXWPFSDT> extractAllSDTs(XWPFDocument doc) {
List<AbstractXWPFSDT> sdts = new ArrayList<AbstractXWPFSDT>();