aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml/src
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2024-06-02 09:39:57 +0000
committerDominik Stadler <centic@apache.org>2024-06-02 09:39:57 +0000
commit329a65973999f106c3273b9328b76c49bb9a26e2 (patch)
treed4d2bc08d08215043bd2e5255bee1e95edda2bb7 /poi-ooxml/src
parentf490e43442e22850a518d51280dceab7602b4e77 (diff)
downloadpoi-329a65973999f106c3273b9328b76c49bb9a26e2.tar.gz
poi-329a65973999f106c3273b9328b76c49bb9a26e2.zip
Avoid NPE and improve error message when saving a package-part fails
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1918117 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java3
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java16
2 files changed, 11 insertions, 8 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java
index 459cbef831..b682cfc141 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java
@@ -89,7 +89,8 @@ public class PackagePropertiesMarshaller implements PartMarshaller {
throws OpenXML4JException {
if (!(part instanceof PackagePropertiesPart))
throw new IllegalArgumentException(
- "'part' must be a PackagePropertiesPart instance.");
+ "'part' must be a PackagePropertiesPart instance, but had: " + part.getClass() +
+ ", check logs while reading.");
propsPart = (PackagePropertiesPart) part;
// Configure the document
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java
index 18c69b616b..4f7aa91704 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java
@@ -63,13 +63,15 @@ public final class XSSFGraphicFrame extends XSSFShape {
for (int i = 0; i < nodes.getLength(); i++) {
final Node node = nodes.item(i);
// if the frame references a chart, associate the chart with this instance
- Node namedItem = node.getAttributes().getNamedItem("r:id");
- if (node.getNodeName().equals("c:chart") && namedItem != null) {
- // this better succeed or the document is invalid
- POIXMLDocumentPart relation = drawing.getRelationById(namedItem.getNodeValue());
- // Do XWPF charts need similar treatment?
- if (relation instanceof XSSFChart) {
- ((XSSFChart) relation).setGraphicFrame(this);
+ if (node.getAttributes() != null) {
+ Node namedItem = node.getAttributes().getNamedItem("r:id");
+ if (node.getNodeName().equals("c:chart") && namedItem != null) {
+ // this better succeed or the document is invalid
+ POIXMLDocumentPart relation = drawing.getRelationById(namedItem.getNodeValue());
+ // Do XWPF charts need similar treatment?
+ if (relation instanceof XSSFChart) {
+ ((XSSFChart) relation).setGraphicFrame(this);
+ }
}
}
}