Author: fanningpj
Date: Sat Jun 14 21:02:34 2025
New Revision: 1926422

URL: http://svn.apache.org/viewvc?rev=1926422&view=rev
Log:
[bug-69715] in DefaultTempFileCreationStrategy, check that dir exists

Modified:
    
poi/trunk/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java?rev=1926422&r1=1926421&r2=1926422&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
 (original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
 Sat Jun 14 21:02:34 2025
@@ -65,14 +65,27 @@ public class DefaultTempFileCreationStra
     }
 
     /**
-     * Creates the strategy allowing to set the
+     * Creates the strategy allowing to set a custom directory for the 
temporary files.
+     * <p>
+     *     If you provide a non-null dir as input, it must be a directory and 
must already exist.
+     *     Since POI 5.4.2, this is checked at construction time. In previous 
versions, it was checked
+     *     at the first call to {@link #createTempFile(String, String)} or 
{@link #createTempDirectory(String)}.
+     * </p>
      *
      * @param dir The directory where the temporary files will be created 
(<code>null</code> to use the default directory).
-     *
+     * @throws IllegalArgumentException if the provided directory does not 
exist or is not a directory
      * @see Files#createTempFile(Path, String, String, FileAttribute[]) 
      */
     public DefaultTempFileCreationStrategy(File dir) {
         this.dir = dir;
+        if (dir != null) {
+            if (!dir.exists()) {
+                throw new IllegalArgumentException("The provided directory 
does not exist: " + dir);
+            }
+            if (!dir.isDirectory()) {
+                throw new IllegalArgumentException("The provided file is not a 
directory: " + dir);
+            }
+        }
     }
 
     @Override



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

Reply via email to