]> source.dussan.org Git - poi.git/commitdiff
Avoid NPE and improve error message when saving a package-part fails
authorDominik Stadler <centic@apache.org>
Sun, 2 Jun 2024 09:39:57 +0000 (09:39 +0000)
committerDominik Stadler <centic@apache.org>
Sun, 2 Jun 2024 09:39:57 +0000 (09:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1918117 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java
test-data/spreadsheet/123233_charts.xlsx [new file with mode: 0644]

index 459cbef8318ddc0b65ec9443d8ec2f4b70f1258d..b682cfc1415028fce790b1971549004cf9379330 100644 (file)
@@ -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
index 18c69b616b3cc824345938c300ed2666a1c745b8..4f7aa9170478164af6e1cff5063869ae690be528 100644 (file)
@@ -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 (file)
index 0000000..be3c1a2
Binary files /dev/null and b/test-data/spreadsheet/123233_charts.xlsx differ