From 8495e7a214b1a0a84d4f53f1f7cffad0f151b8a8 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Tue, 8 Oct 2024 16:41:41 +0200 Subject: [PATCH] double check existence before throwing an exception --- .../java/lucee/commons/io/res/type/file/FileResource.java | 4 +++- loader/build.xml | 2 +- loader/pom.xml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/lucee/commons/io/res/type/file/FileResource.java b/core/src/main/java/lucee/commons/io/res/type/file/FileResource.java index 603c8858c8..f41ae93992 100644 --- a/core/src/main/java/lucee/commons/io/res/type/file/FileResource.java +++ b/core/src/main/java/lucee/commons/io/res/type/file/FileResource.java @@ -263,7 +263,9 @@ public OutputStream getOutputStream(boolean append) throws IOException { provider.lock(this); try { if (!super.exists() && !super.createNewFile()) { - throw new IOException("Can't create file [" + this + "]"); + // It's possible that another process (outside this JVM) has already created the file + // after our initial check, so we perform a double check before throwing an exception. + if (!super.exists()) throw new IOException("Can't create file [" + this + "]"); } return new BufferedOutputStream(new ResourceOutputStream(this, new FileOutputStream(this, append))); } diff --git a/loader/build.xml b/loader/build.xml index 8e3e9d2017..4c88b795dd 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 632c475cc5..613713c546 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.0.4.9-SNAPSHOT + 6.0.4.10-SNAPSHOT jar Lucee Loader Build