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

stbischof pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 326327004c FELIX-6794: Fileinstall hangs (endless loop) when 
java.io.tempdir is not writable, use java.nio.Files instead, improve diagnostics
326327004c is described below

commit 326327004ca296c2731d6b0a0a9e49bd882c101a
Author: Julian Reschke <[email protected]>
AuthorDate: Fri Aug 1 12:08:38 2025 +0100

    FELIX-6794: Fileinstall hangs (endless loop) when java.io.tempdir is not 
writable, use java.nio.Files instead, improve diagnostics
---
 .../felix/fileinstall/internal/DirectoryWatcher.java | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git 
a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
 
b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
index 8fe89f54c6..0e325bc454 100644
--- 
a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
+++ 
b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
@@ -27,6 +27,7 @@ import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -37,7 +38,6 @@ import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.jar.JarInputStream;
@@ -607,19 +607,11 @@ public class DirectoryWatcher extends Thread implements 
BundleListener
     {
         if (tmpDir == null)
         {
-            File javaIoTmpdir = new File(System.getProperty("java.io.tmpdir"));
-            if (!javaIoTmpdir.exists() && !javaIoTmpdir.mkdirs()) {
-                throw new IllegalStateException("Unable to create temporary 
directory " + javaIoTmpdir);
-            }
-            Random random = new Random();
-            while (tmpDir == null)
-            {
-                File f = new File(javaIoTmpdir, "fileinstall-" + 
Long.toString(random.nextLong()));
-                if (!f.exists() && f.mkdirs())
-                {
-                    tmpDir = f;
-                    tmpDir.deleteOnExit();
-                }
+            try {
+                tmpDir = Files.createTempDirectory("fileinstall-").toFile();
+                tmpDir.deleteOnExit();
+            } catch (IOException ex) {
+                throw new IllegalStateException("Cannot create temp 
directory", ex);
             }
         }
         else

Reply via email to