From 329a65973999f106c3273b9328b76c49bb9a26e2 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 2 Jun 2024 09:39:57 +0000 Subject: [PATCH] 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 --- .../PackagePropertiesMarshaller.java | 3 ++- .../poi/xssf/usermodel/XSSFGraphicFrame.java | 16 +++++++++------- test-data/spreadsheet/123233_charts.xlsx | Bin 0 -> 12957 bytes 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 test-data/spreadsheet/123233_charts.xlsx 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); + } } } } diff --git a/test-data/spreadsheet/123233_charts.xlsx b/test-data/spreadsheet/123233_charts.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..be3c1a2f91f250f3bbd0ae70da5959870d0a779a GIT binary patch literal 12957 zcmeIYWl)^kvoDM@Sa2r+g1b9G6WrY$g1fr}cXxMp5AG1$T@&2hUr7Go_c0xb@l4*)$&^{B?=0L0t9&Z{7EP;UpSi5=o)HU+uHnk&`~>@nI0;uTP!l8 zxQ&*N#c-MOAP?9hOeGz5#%=2Gz+ed9P1und?k>!TMS=)(T)96Axp}DAC&OaXL(+DO zYMe!Fr)7(NK5;+RHG>RsiGjTwsVy|&!P#@xW18aT9w}Sd#X=8g0LX&yKLV+Fa5rJF z##IZ5af0;&i;wU&e22ZPMex$cSW@;0zhQ#&>~AH~=R&F)Q1BZXi%wbW6PRVR2(?7| zkOt(|2gY?Kv@t4inm?4g-5$fPiW?9>tnC>Y0ogvQ(SAAZ8)quXRrI+A^vbyh_V(e>IehyH zvb+#M-EV5RkZ2!@{kD%p31VXD(Un5g4+M=tI*zmp)8Yuwp)SnA6vl3epWTyeA^hlz zkM$A|?{aNUw9-n-;Uap-u9g!0t#n{QO=~NxaCjx%?;aUp&9tT*g-OH&&XT3{nFWkv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