mirror of https://github.com/apache/poi.git
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:
parent
960cbb7714
commit
af9142e4b7
|
@ -47,6 +47,9 @@ public class XWPFSDTContent implements ISDTContent {
|
|||
private List<ISDTContents> bodyElements = new ArrayList<>();
|
||||
|
||||
public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent) {
|
||||
if (sdtRun == null) {
|
||||
return;
|
||||
}
|
||||
for (CTR ctr : sdtRun.getRArray()) {
|
||||
XWPFRun run = new XWPFRun(ctr, parent);
|
||||
// runs.add(run);
|
||||
|
@ -55,6 +58,9 @@ public class XWPFSDTContent implements ISDTContent {
|
|||
}
|
||||
|
||||
public XWPFSDTContent(CTSdtContentBlock block, IBody part, IRunBody parent) {
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
XmlCursor cursor = block.newCursor();
|
||||
cursor.selectPath("./*");
|
||||
while (cursor.toNextSelection()) {
|
||||
|
|
|
@ -74,7 +74,7 @@ public class TestFonts {
|
|||
// currently linux and mac return quite different values
|
||||
private static final int[] expected_sizes = {
|
||||
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,
|
||||
348, // Windows 10, 15.6" 3840x2160
|
||||
362, // Windows 10, 13.3" 1080p high-dpi
|
||||
|
|
|
@ -148,6 +148,19 @@ public final class TestXWPFSDT {
|
|||
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) {
|
||||
|
||||
List<XWPFAbstractSDT> sdts = new ArrayList<>();
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue