diff --git a/documentation-generator/src/main/java/tech/picnic/errorprone/plugin/DocumentationGeneratorTaskListener.java b/documentation-generator/src/main/java/tech/picnic/errorprone/plugin/DocumentationGeneratorTaskListener.java index d9dfdd289a6..050856deacc 100644 --- a/documentation-generator/src/main/java/tech/picnic/errorprone/plugin/DocumentationGeneratorTaskListener.java +++ b/documentation-generator/src/main/java/tech/picnic/errorprone/plugin/DocumentationGeneratorTaskListener.java @@ -18,6 +18,7 @@ import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Optional; @@ -38,12 +39,12 @@ final class DocumentationGeneratorTaskListener implements TaskListener { this.basePath = path.substring(path.indexOf('=') + 1) + File.separator + "docs"; // XXX: Should we extract this method? - Path docsPath = Paths.get(basePath); try { + Path docsPath = Paths.get(basePath); Files.createDirectories(docsPath); - } catch (IOException e) { + } catch (IOException | InvalidPathException e) { throw new IllegalStateException( - String.format("Error while creating directory '%s'", docsPath), e); + String.format("Error while creating directory with path '%s'", basePath), e); } } diff --git a/documentation-generator/src/test/java/tech/picnic/errorprone/plugin/DocumentationGeneratorBugPatternTest.java b/documentation-generator/src/test/java/tech/picnic/errorprone/plugin/DocumentationGeneratorBugPatternTest.java index c081faced8c..e420ebf8611 100644 --- a/documentation-generator/src/test/java/tech/picnic/errorprone/plugin/DocumentationGeneratorBugPatternTest.java +++ b/documentation-generator/src/test/java/tech/picnic/errorprone/plugin/DocumentationGeneratorBugPatternTest.java @@ -9,22 +9,22 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.io.TempDir; final class DocumentationGeneratorBugPatternTest extends DocumentationGeneratorCompilerBasedTest { - @Test @EnabledOnOs(WINDOWS) + @Test void wrongPathFailsWindows() { wrongPathFails('?'); } - @Test @DisabledOnOs(WINDOWS) + @Test void wrongPathFailsOtherOperatingSystems() { + // Strictly speaking we are validating here that we cannot write to a RO FS. wrongPathFails('/'); } @@ -32,7 +32,8 @@ private void wrongPathFails(char invalidCharacter) { String invalidPath = invalidCharacter + "wrong-path"; assertThatThrownBy(() -> compile(invalidPath)) .isInstanceOf(IllegalStateException.class) - .hasMessage("Error while creating directory '%s'", Paths.get(invalidPath, "docs")); + .hasMessage( + "Error while creating directory with path '%s'", invalidPath + File.separator + "docs"); } @Test