From c5ca5ae0657250669349304d5a0ddf1f601656a3 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 14 Jun 2025 21:02:34 +0000 Subject: [PATCH] [bug-69715] in DefaultTempFileCreationStrategy, check that dir exists git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1926422 13f79535-47bb-0310-9956-ffa450edef68 --- .../util/DefaultTempFileCreationStrategy.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java b/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java index 9b2e711ed4..ea07dc7478 100644 --- a/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java +++ b/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java @@ -65,14 +65,27 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy } /** - * Creates the strategy allowing to set the + * Creates the strategy allowing to set a custom directory for the temporary files. + *

+ * 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)}. + *

* * @param dir The directory where the temporary files will be created (null 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