From 46ae0a8c60ad155b07bb90eb95b5e9fc7e4e75dc Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 3 Nov 2022 11:47:34 +0000 Subject: [PATCH] [bug-66337] do not warn about missing SummaryInformation when creating new HSSFWorkbooks. Thanks to Nicolas Herzog. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905045 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/poi/POIDocument.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/POIDocument.java b/poi/src/main/java/org/apache/poi/POIDocument.java index 6c6aacd6e1..608c14be6d 100644 --- a/poi/src/main/java/org/apache/poi/POIDocument.java +++ b/poi/src/main/java/org/apache/poi/POIDocument.java @@ -122,7 +122,7 @@ public abstract class POIDocument implements Closeable { */ public void createInformationProperties() { if (!initialized) { - readProperties(); + readProperties(false); } if (sInf == null) { sInf = PropertySetFactory.newSummaryInformation(); @@ -140,14 +140,26 @@ public abstract class POIDocument implements Closeable { */ @Internal public void readProperties() { + readProperties(true); + } + + /** + * Find, and create objects for, the standard Document Information Properties (HPSF). + * If a given property set is missing or corrupt, it will remain null. + * + * @param warnIfNull log a warning if any of the property sets come back as null. + * The directory is null when creating a new document from scratch + */ + @Internal + public void readProperties(boolean warnIfNull) { if (initialized) { return; } - DocumentSummaryInformation dsi = readPropertySet(DocumentSummaryInformation.class, DocumentSummaryInformation.DEFAULT_STREAM_NAME); + DocumentSummaryInformation dsi = readPropertySet(DocumentSummaryInformation.class, DocumentSummaryInformation.DEFAULT_STREAM_NAME, warnIfNull); if (dsi != null) { dsInf = dsi; } - SummaryInformation si = readPropertySet(SummaryInformation.class, SummaryInformation.DEFAULT_STREAM_NAME); + SummaryInformation si = readPropertySet(SummaryInformation.class, SummaryInformation.DEFAULT_STREAM_NAME, warnIfNull); if (si != null) { sInf = si; } @@ -157,7 +169,7 @@ public abstract class POIDocument implements Closeable { } @SuppressWarnings("unchecked") - private T readPropertySet(Class clazz, String name) { + private T readPropertySet(Class clazz, String name, boolean warnIfNull) { String localName = clazz.getName().substring(clazz.getName().lastIndexOf('.')+1); try { PropertySet ps = getPropertySet(name); @@ -166,7 +178,9 @@ public abstract class POIDocument implements Closeable { } else if (ps != null) { LOG.atWarn().log("{} property set came back with wrong class - {}", localName, ps.getClass().getName()); } else { - LOG.atWarn().log("{} property set came back as null", localName); + if (warnIfNull) { + LOG.atWarn().log("{} property set came back as null", localName); + } } } catch (IOException e) { LOG.atError().withThrowable(e).log("can't retrieve property set"); -- 2.39.5