Skip to content

Commit 2abb948

Browse files
committed
Do not try to translate classes in META-INF/versions
In a multirelease-jar environment, there could be classes under META-INF/versions, which retrolambda would try to translate. As per definition, these are Java classes newer than Java 1.8, so they shouldn't be processed at all, especially since it is expected that there is at least some version (hopefully 1.8 or older) of that class in the path that is not prefixed by META-INF/versions. Extend FilteringFileVisitor to never visit /META-INF/versions, and modify FilteringFileVisitor so it's usable in all cases, even when no other filtering is required.
1 parent fbd82c9 commit 2abb948

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

retrolambda/src/main/java/net/orfjackal/retrolambda/Retrolambda.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ protected void visitResource(Path relativePath, byte[] content) throws IOExcepti
103103
}
104104

105105
static void visitFiles(Path inputDir, List<Path> includedFiles, FileVisitor<Path> visitor) throws IOException {
106-
if (includedFiles != null) {
107-
visitor = new FilteringFileVisitor(includedFiles, visitor);
108-
}
106+
visitor = new FilteringFileVisitor(includedFiles, visitor);
109107
Files.walkFileTree(inputDir, visitor);
110108
}
111109

retrolambda/src/main/java/net/orfjackal/retrolambda/files/FilteringFileVisitor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class FilteringFileVisitor implements FileVisitor<Path> {
1515
private final FileVisitor<? super Path> target;
1616

1717
public FilteringFileVisitor(Collection<Path> fileFilter, FileVisitor<Path> target) {
18-
this.fileFilter = new HashSet<>(fileFilter);
18+
this.fileFilter = fileFilter == null ? null : new HashSet<>(fileFilter);
1919
this.target = target;
2020
}
2121

@@ -26,12 +26,15 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
2626

2727
@Override
2828
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
29+
if (dir.toString().endsWith("/META-INF/versions")) {
30+
return FileVisitResult.SKIP_SUBTREE;
31+
}
2932
return target.preVisitDirectory(dir, attrs);
3033
}
3134

3235
@Override
3336
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
34-
if (fileFilter.contains(file)) {
37+
if (fileFilter == null || fileFilter.contains(file)) {
3538
return target.visitFile(file, attrs);
3639
} else {
3740
return FileVisitResult.CONTINUE;

0 commit comments

Comments
 (0)