From 098fc6fdb7d005d56ace195e1c50754af98768db Mon Sep 17 00:00:00 2001 From: Chetan Narsude Date: Sun, 22 Oct 2023 19:27:25 -0700 Subject: [PATCH] fix the crash #1858 when the maven build dir is a softlink to an actual directory --- .../diffplug/spotless/maven/incremental/FileIndex.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/FileIndex.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/FileIndex.java index 8330319cfb..8f300d7204 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/FileIndex.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/FileIndex.java @@ -144,7 +144,15 @@ private void ensureParentDirExists() { throw new IllegalStateException("Index file does not have a parent dir: " + indexFile); } try { - Files.createDirectories(parentDir); + bool create = false; + if (Files.exists(parentDir, LinkOption.NO_FOLLOW)) { + Path realPath = parentDir.toRealPath(); + if (!Files.exists(realPath)) { + Files.createDirectories(realPath); + } + } else { + Files.createDirectories(parentDir); + } } catch (IOException e) { throw new UncheckedIOException("Unable to create parent directory for the index file: " + indexFile, e); }