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

acosentino pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 50a4d396d37c20c5be6aa0a5a4a8b85d2923fb5c
Author: Andrea Cosentino <anco...@gmail.com>
AuthorDate: Tue Jun 6 17:06:33 2023 +0200

    CAMEL-19421 - Camel-Jira: Use Files.createTempFile in FileConverter instead 
of creating File directly
    
    Signed-off-by: Andrea Cosentino <anco...@gmail.com>
---
 .../org/apache/camel/component/jira/FileConverter.java | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git 
a/components/camel-jira/src/main/java/org/apache/camel/component/jira/FileConverter.java
 
b/components/camel-jira/src/main/java/org/apache/camel/component/jira/FileConverter.java
index d7d2f3642d7..e19d85e4ef9 100644
--- 
a/components/camel-jira/src/main/java/org/apache/camel/component/jira/FileConverter.java
+++ 
b/components/camel-jira/src/main/java/org/apache/camel/component/jira/FileConverter.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.jira;
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.StandardOpenOption;
 
 import org.apache.camel.Converter;
@@ -34,20 +35,13 @@ public final class FileConverter {
     @Converter
     public static File genericToFile(GenericFile<File> genericFile, Exchange 
exchange) throws IOException {
         Object body = genericFile.getBody();
-        File file;
+        File file = null;
+        Path path;
         if (body instanceof byte[]) {
             byte[] bos = (byte[]) body;
-            String destDir = System.getProperty("java.io.tmpdir");
-            if (destDir != null && !destDir.endsWith(File.separator)) {
-                destDir += File.separator;
-            }
-            file = new File(destDir, genericFile.getFileName());
-            if (!file.getCanonicalPath().startsWith(destDir)) {
-                throw new IOException("File is not jailed to the destination 
directory");
-            }
-            Files.write(file.toPath(), bos, StandardOpenOption.CREATE);
-            // delete the temporary file on exit, as other routing may need 
the file for post processing
-            file.deleteOnExit();
+            path = Files.createTempFile(genericFile.getFileName(), null, null);
+            Files.write(path, bos, StandardOpenOption.CREATE);
+            path.toFile().deleteOnExit();
         } else {
             file = (File) body;
         }

Reply via email to