diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java index 99ab66a7e..f39c5cf48 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java @@ -47,6 +47,9 @@ public class XWPFSDTContent implements ISDTContent { private List 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()) { diff --git a/src/ooxml/testcases/org/apache/poi/sl/TestFonts.java b/src/ooxml/testcases/org/apache/poi/sl/TestFonts.java index b7a6d16a5..f35065de7 100644 --- a/src/ooxml/testcases/org/apache/poi/sl/TestFonts.java +++ b/src/ooxml/testcases/org/apache/poi/sl/TestFonts.java @@ -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 diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java index deac5c09a..9388e0871 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java @@ -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 sdts = extractAllSDTs(doc); + assertEquals(1, sdts.size()); + assertEquals("", sdts.get(0).getTag()); + assertEquals("", sdts.get(0).getTitle()); + } + private List extractAllSDTs(XWPFDocument doc) { List sdts = new ArrayList<>(); diff --git a/test-data/document/Bug62859.docx b/test-data/document/Bug62859.docx new file mode 100644 index 000000000..e0ede4a83 Binary files /dev/null and b/test-data/document/Bug62859.docx differ