Skip to content

Commit

Permalink
Merge pull request #241 from gradle/leo/graceful-fallback
Browse files Browse the repository at this point in the history
Ignore asm version errors when parsing class for retry
  • Loading branch information
leonard84 authored Nov 27, 2023
2 parents 6b765bd + ac95bcc commit 3ec652c
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
package org.gradle.testretry.internal.testsreader;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
Expand All @@ -34,6 +37,8 @@

public final class TestsReader {

private static final Logger LOGGER = LoggerFactory.getLogger(TestsReader.class);

private final Set<File> testClassesDirs;
private final Iterable<File> classpath;

Expand All @@ -60,11 +65,18 @@ public <R> Optional<R> readClass(String className, Supplier<? extends Visitor<R>
}
}

@Nullable
private <R> R visitClassFile(File file, Visitor<R> visitor) {
try (InputStream in = new FileInputStream(file)) {
try (InputStream in = Files.newInputStream(file.toPath())) {
return visit(in, visitor);
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (IllegalArgumentException iae) {
if (iae.getMessage().startsWith("Unsupported class file major version")) {
LOGGER.warn("Could not parse class, ignoring for retry", iae);
return null;
}
throw iae;
}
}

Expand Down

0 comments on commit 3ec652c

Please sign in to comment.