diff options
author | Tim Allison <tallison@apache.org> | 2016-11-04 15:06:17 +0000 |
---|---|---|
committer | Tim Allison <tallison@apache.org> | 2016-11-04 15:06:17 +0000 |
commit | 14645fe5a814c2771fbfddae019a61de18793344 (patch) | |
tree | cecaa3eb2aa00fbda6045696afd7577547fa796d /src | |
parent | 5f2951ebc64be8a0501ef35cf3c1647fc6ea2c84 (diff) | |
download | poi-14645fe5a814c2771fbfddae019a61de18793344.tar.gz poi-14645fe5a814c2771fbfddae019a61de18793344.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFSDT.java | 54 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java | 10 |
2 files changed, 39 insertions, 25 deletions
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<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>(); |