From bbef66dee3c8899ead321fcb57447455a02939cc Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 13 Dec 2021 12:23:13 +0000 Subject: [PATCH] [bug-65741] issue with null date values causing npes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895877 13f79535-47bb-0310-9956-ffa450edef68 --- .../opc/internal/PackagePropertiesPart.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java index d6a625baeb..e390d504e8 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java +++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java @@ -428,10 +428,12 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setCreatedProperty(String created) { - try { - this.created = setDateValue(created); - } catch (InvalidFormatException e) { - throw new IllegalArgumentException("Date for created could not be parsed: " + created, e); + if (created != null) { + try { + this.created = setDateValue(created); + } catch (InvalidFormatException e) { + throw new IllegalArgumentException("Date for created could not be parsed: " + created, e); + } } } @@ -550,11 +552,13 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setLastPrintedProperty(String lastPrinted) { - try { - this.lastPrinted = setDateValue(lastPrinted); - } catch (InvalidFormatException e) { - throw new IllegalArgumentException("lastPrinted : " - + e.getLocalizedMessage(), e); + if (lastPrinted != null) { + try { + this.lastPrinted = setDateValue(lastPrinted); + } catch (InvalidFormatException e) { + throw new IllegalArgumentException("lastPrinted : " + + e.getLocalizedMessage(), e); + } } } @@ -575,11 +579,13 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setModifiedProperty(String modified) { - try { - this.modified = setDateValue(modified); - } catch (InvalidFormatException e) { - throw new IllegalArgumentException("modified : " - + e.getLocalizedMessage(), e); + if (modified != null) { + try { + this.modified = setDateValue(modified); + } catch (InvalidFormatException e) { + throw new IllegalArgumentException("modified : " + + e.getLocalizedMessage(), e); + } } } @@ -670,7 +676,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP * Convert a string value represented a date into a {@code Optional} * * @throws InvalidFormatException - * Throws if the date format isnot valid. + * Throws if the date format is not valid. */ private Optional setDateValue(String dateStr) throws InvalidFormatException { if (dateStr == null || dateStr.isEmpty()) {