Author: fanningpj
Date: Thu Nov  3 11:47:34 2022
New Revision: 1905045

URL: http://svn.apache.org/viewvc?rev=1905045&view=rev
Log:
[bug-66337] do not warn about missing SummaryInformation when creating new 
HSSFWorkbooks. Thanks to Nicolas Herzog.

Modified:
    poi/trunk/poi/src/main/java/org/apache/poi/POIDocument.java

Modified: poi/trunk/poi/src/main/java/org/apache/poi/POIDocument.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/POIDocument.java?rev=1905045&r1=1905044&r2=1905045&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/POIDocument.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/POIDocument.java Thu Nov  3 
11:47:34 2022
@@ -122,7 +122,7 @@ public abstract class POIDocument implem
      */
     public void createInformationProperties() {
         if (!initialized) {
-            readProperties();
+            readProperties(false);
         }
         if (sInf == null) {
             sInf = PropertySetFactory.newSummaryInformation();
@@ -140,14 +140,26 @@ public abstract class POIDocument implem
      */
     @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 implem
     }
 
     @SuppressWarnings("unchecked")
-    private <T> T readPropertySet(Class<T> clazz, String name) {
+    private <T> T readPropertySet(Class<T> 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 implem
             } 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");



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to