bug 62859 -- fix two potential NPEs when initializing XWPFSDTContent

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1844920 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tim Allison 2018-10-26 19:06:18 +00:00
parent 960cbb7714
commit af9142e4b7
4 changed files with 20 additions and 1 deletions

View File

@ -47,6 +47,9 @@ public class XWPFSDTContent implements ISDTContent {
private List<ISDTContents> bodyElements = new ArrayList<>(); private List<ISDTContents> bodyElements = new ArrayList<>();
public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent) { public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent) {
if (sdtRun == null) {
return;
}
for (CTR ctr : sdtRun.getRArray()) { for (CTR ctr : sdtRun.getRArray()) {
XWPFRun run = new XWPFRun(ctr, parent); XWPFRun run = new XWPFRun(ctr, parent);
// runs.add(run); // runs.add(run);
@ -55,6 +58,9 @@ public class XWPFSDTContent implements ISDTContent {
} }
public XWPFSDTContent(CTSdtContentBlock block, IBody part, IRunBody parent) { public XWPFSDTContent(CTSdtContentBlock block, IBody part, IRunBody parent) {
if (block == null) {
return;
}
XmlCursor cursor = block.newCursor(); XmlCursor cursor = block.newCursor();
cursor.selectPath("./*"); cursor.selectPath("./*");
while (cursor.toNextSelection()) { while (cursor.toNextSelection()) {

View File

@ -74,7 +74,7 @@ public class TestFonts {
// currently linux and mac return quite different values // currently linux and mac return quite different values
private static final int[] expected_sizes = { private static final int[] expected_sizes = {
304, // windows 10, 1080p, MS Office 2016, system text scaling 100% instead of default 125% 304, // windows 10, 1080p, MS Office 2016, system text scaling 100% instead of default 125%
306, // Windows 10, 15.6" 3840x2160 306, 308,// Windows 10, 15.6" 3840x2160
311, 312, 313, 318, 311, 312, 313, 318,
348, // Windows 10, 15.6" 3840x2160 348, // Windows 10, 15.6" 3840x2160
362, // Windows 10, 13.3" 1080p high-dpi 362, // Windows 10, 13.3" 1080p high-dpi

View File

@ -148,6 +148,19 @@ public final class TestXWPFSDT {
assertEquals("", sdts.get(0).getTitle()); assertEquals("", sdts.get(0).getTitle());
} }
@Test
public void test62859() throws IOException {
//this doesn't test the exact code path for this issue, but
//it does test for a related issue, and the fix fixes both.
//We should try to add the actual triggering document
//to our test suite.
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug62859.docx");
List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
assertEquals(1, sdts.size());
assertEquals("", sdts.get(0).getTag());
assertEquals("", sdts.get(0).getTitle());
}
private List<XWPFAbstractSDT> extractAllSDTs(XWPFDocument doc) { private List<XWPFAbstractSDT> extractAllSDTs(XWPFDocument doc) {
List<XWPFAbstractSDT> sdts = new ArrayList<>(); List<XWPFAbstractSDT> sdts = new ArrayList<>();

Binary file not shown.