diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFSDT.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFSDT.java index 2cf42f1862..4db163de2d 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFSDT.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFSDT.java @@ -1,18 +1,18 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. ==================================================================== */ package org.apache.poi.xwpf.usermodel; @@ -33,18 +33,22 @@ public abstract class AbstractXWPFSDT implements ISDTContents { private final IBody part; public AbstractXWPFSDT(CTSdtPr pr, IBody part) { - - CTString[] aliases = pr.getAliasArray(); - if (aliases != null && aliases.length > 0) { - title = aliases[0].getVal(); - } else { + if (pr == null) { title = ""; - } - CTString[] tags = pr.getTagArray(); - if (tags != null && tags.length > 0) { - tag = tags[0].getVal(); - } else { tag = ""; + } else { + CTString[] aliases = pr.getAliasArray(); + if (aliases != null && aliases.length > 0) { + title = aliases[0].getVal(); + } else { + title = ""; + } + CTString[] tags = pr.getTagArray(); + if (tags != null && tags.length > 0) { + tag = tags[0].getVal(); + } else { + tag = ""; + } } this.part = part; 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 b008763ca6..0f625fbd90 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java @@ -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 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();