Skip to content

Commit 8696c79

Browse files
committed
fix: Path.getFileName() null handling
1 parent 6f23f9a commit 8696c79

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

jdoc-cucumber-gradle-plugin/src/main/java/org/bool/jdoc/cucumber/gradle/JdocCucumberAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.nio.file.Files;
1212
import java.nio.file.Path;
1313
import java.util.List;
14+
import java.util.Objects;
1415
import java.util.stream.Stream;
1516

1617
public class JdocCucumberAction implements JdocAction {
@@ -41,7 +42,7 @@ public void generate(File sourceFile, String baseName, Path outputPath) {
4142
public void delete(File sourceFile, String baseName, Path outputPath) {
4243
try (Stream<Path> files = Files.list(outputPath)) {
4344
String prefix = baseName + "_";
44-
files.filter(p -> matches(p.getFileName().toString(), prefix, ".feature"))
45+
files.filter(p -> matches(Objects.toString(p.getFileName(), ""), prefix, ".feature"))
4546
.forEach(this::delete);
4647
} catch (IOException e) {
4748
throw new UncheckedIOException("Error listing files: " + outputPath, e);

jdoc-junit-engine-commons/src/main/java/org/bool/jdoc/core/JdocSpecReader.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
1111
import java.util.List;
12+
import java.util.Objects;
1213
import java.util.stream.Collectors;
1314
import java.util.stream.Stream;
1415

@@ -38,15 +39,17 @@ public JdocSpecReader(String lang) {
3839
*/
3940
public List<SpecSource> readSpecs(List<DiscoverySelector> selectors) {
4041
return selectors.stream()
41-
.flatMap(this::streamFiles).distinct()
42-
.map(parser::parse).collect(Collectors.toList());
42+
.flatMap(this::streamFiles)
43+
.distinct()
44+
.map(parser::parse)
45+
.collect(Collectors.toList());
4346
}
4447

4548
@SneakyThrows
4649
private Stream<Path> streamFiles(DiscoverySelector selector) {
4750
if (selector instanceof DirectorySelector) {
4851
return Files.walk(((DirectorySelector) selector).getPath())
49-
.filter(path -> path.getFileName().toString().endsWith(".java"));
52+
.filter(path -> Objects.toString(path.getFileName(), "").endsWith(".java"));
5053
}
5154
if (selector instanceof FileSelector) {
5255
return Stream.of(((FileSelector) selector).getPath());

0 commit comments

Comments
 (0)