This is an automated email from the ASF dual-hosted git repository.
SbloodyS pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 7eed4bf825 [Chore][Common] Handle parentless paths in FileUtils
(#18408)
7eed4bf825 is described below
commit 7eed4bf825eff4a9066974253da20ce3c153c987
Author: 陈家名 <[email protected]>
AuthorDate: Wed Aug 19 10:01:21 2026 +0800
[Chore][Common] Handle parentless paths in FileUtils (#18408)
Co-authored-by: xiangzihao <[email protected]>
---
.../apache/dolphinscheduler/common/utils/FileUtils.java | 3 ++-
.../dolphinscheduler/common/utils/FileUtilsTest.java | 15 +++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
index a105481089..ec5d2ac321 100644
---
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
+++
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
@@ -128,7 +128,8 @@ public class FileUtils {
FileOutputStream fos = null;
try {
File distFile = new File(filePath);
- if (!distFile.getParentFile().exists() &&
!distFile.getParentFile().mkdirs()) {
+ File parentFile = distFile.getParentFile();
+ if (parentFile != null && !parentFile.exists() &&
!parentFile.mkdirs()) {
log.error("mkdir parent failed");
return false;
}
diff --git
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
index 2396d52c20..0fdcc2b04b 100644
---
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
+++
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
@@ -93,6 +93,21 @@ public class FileUtilsTest {
}
}
+ @Test
+ public void testWriteContent2FileWithoutParentDirectory() throws
IOException {
+ Path filePath = Paths.get("write-content-" + folder.getFileName() +
".txt");
+ String content = "test content";
+
+ try {
+ Assertions.assertTrue(FileUtils.writeContent2File(content,
filePath.toString()));
+ try (InputStream inputStream = Files.newInputStream(filePath)) {
+ Assertions.assertEquals(content,
FileUtils.readFile2Str(inputStream));
+ }
+ } finally {
+ Files.deleteIfExists(filePath);
+ }
+ }
+
@Test
public void testDirectoryTraversal() {
// test case which do not directory traversal