This is an automated email from the ASF dual-hosted git repository. coheigea pushed a commit to branch coheigea/maybeDeleteDefaultTempDir in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 6a557fe9bb8b18f1538c3672343b98adc0a0cc33 Author: Colm O hEigeartaigh <[email protected]> AuthorDate: Fri Nov 27 15:55:17 2026 +0000 Fix NPE in maybeDeleteDefaultTempDir and warn when TempDirectory is ignored --- core/src/main/java/org/apache/cxf/helpers/FileUtils.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/cxf/helpers/FileUtils.java b/core/src/main/java/org/apache/cxf/helpers/FileUtils.java index 44894814f1c..c923b04b2db 100644 --- a/core/src/main/java/org/apache/cxf/helpers/FileUtils.java +++ b/core/src/main/java/org/apache/cxf/helpers/FileUtils.java @@ -82,6 +82,10 @@ public final class FileUtils { File f = new File(s); if (f.mkdirs()) { defaultTempDir = f; + } else if (f.isDirectory()) { + LogUtils.getL7dLogger(FileUtils.class).warning("The directory " + s + " set by " + + FileUtils.class.getName() + ".TempDirectory already exists and is ignored; " + + "a directory under java.io.tmpdir is used instead"); } } // also create a new directory if ours was removed, e.g. by a tmp cleaner, while the JVM was running. @@ -99,7 +103,9 @@ public final class FileUtils { } public static synchronized void maybeDeleteDefaultTempDir() { - if (defaultTempDir != null) { + // with no shutdown hook the directory was configured via the TempDirectory property, + // so it is managed outside of CXF and must not be removed + if (defaultTempDir != null && shutdownHook != null) { Runtime.getRuntime().gc(); // attempt a garbage collect to close any files String[] files = defaultTempDir.list(); if (files != null && files.length > 0) {
