From ca68b6346e7433f7c01a92e640bd3c352d5a529f Mon Sep 17 00:00:00 2001 From: Rene Pfeuffer Date: Wed, 3 Jul 2019 17:27:59 +0200 Subject: [PATCH] Double check directory creation --- scm-core/src/main/java/sonia/scm/util/IOUtil.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/util/IOUtil.java b/scm-core/src/main/java/sonia/scm/util/IOUtil.java index d71f8a36fc..16f84d1031 100644 --- a/scm-core/src/main/java/sonia/scm/util/IOUtil.java +++ b/scm-core/src/main/java/sonia/scm/util/IOUtil.java @@ -471,8 +471,14 @@ public final class IOUtil { if (!directory.exists() &&!directory.mkdirs()) { - throw new IllegalStateException( - "could not create directory ".concat(directory.getPath())); + // Sometimes, the previous check simply has the wrong result (either the 'exists()' returnes false though the + // directory exists or 'mkdirs()' returns false though the directory was created successfully. + // We therefore have to double check here. Funny though, in these cases a second check with 'directory.exists()' + // still returns false. As it seems, 'directory.getAbsoluteFile().exists()' creates a new object that fixes this + // problem. + if (!directory.getAbsoluteFile().exists()) { + throw new IllegalStateException("could not create directory ".concat(directory.getPath())); + } } }