Prevent IOException in CheckAutoConfigurationClasses

This commit ensures that before walking a source root, the Gradle plugin
checks that it exists. This situation can only happen when a Gradle
plugin adds new roots to SourceSets, but there are no sources in them.

Fixes gh-47142
This commit is contained in:
Brian Clozel 2025-09-10 11:43:54 +02:00
parent 450eb48303
commit 4d0cce7791
1 changed files with 11 additions and 9 deletions

View File

@ -136,15 +136,17 @@ public abstract class CheckAutoConfigurationClasses extends AutoConfigurationImp
private List<File> classFiles() {
List<File> classFiles = new ArrayList<>();
for (File root : this.classpath.getFiles()) {
try (Stream<Path> files = Files.walk(root.toPath())) {
files.forEach((file) -> {
if (Files.isRegularFile(file) && file.getFileName().toString().endsWith(".class")) {
classFiles.add(file.toFile());
}
});
}
catch (IOException ex) {
throw new UncheckedIOException(ex);
if (root.exists()) {
try (Stream<Path> files = Files.walk(root.toPath())) {
files.forEach((file) -> {
if (Files.isRegularFile(file) && file.getFileName().toString().endsWith(".class")) {
classFiles.add(file.toFile());
}
});
}
catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
}
return classFiles;