This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 4.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/4.1.x-fixes by this push:
     new fbc07f47d18 Fix NPE in maybeDeleteDefaultTempDir and warn when 
TempDirectory is ignored (#3797)
fbc07f47d18 is described below

commit fbc07f47d18b7a9a193e051fed0640d975fceabc
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Mon Nov 30 08:06:42 2026 +0000

    Fix NPE in maybeDeleteDefaultTempDir and warn when TempDirectory is ignored 
(#3797)
    
    (cherry picked from commit eeff6573c57b3659de9ea74f297a4de349221be2)
---
 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 bcd0c78288b..ff52a5db069 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) {

Reply via email to