Skip to content

Commit

Permalink
Avoid using lambdas and streams in <clinit> (#387)
Browse files Browse the repository at this point in the history
This shouldn't make a difference in the real world,
but those method handles sure don't look nice in
flamegraphs
  • Loading branch information
geoand authored Jan 5, 2025
1 parent bfb1309 commit b5beae1
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.nio.file.spi.FileSystemProvider;
import java.util.Enumeration;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
import java.util.function.Function;

Expand Down Expand Up @@ -109,10 +110,19 @@ public static void consumeAsPath(URL url, Consumer<Path> consumer) {

static {
final ClassLoader ccl = Thread.currentThread().getContextClassLoader();
FileSystemProvider provider = null;
try {
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
JAR_PROVIDER = FileSystemProvider.installedProviders().stream().filter(p -> p.getScheme().equals("jar")).findFirst()
.orElseThrow();
for (FileSystemProvider p : FileSystemProvider.installedProviders()) {
if (p.getScheme().equals("jar")) {
provider = p;
break;
}
}
if (provider == null) {
throw new NoSuchElementException("Unable to find provider supporting jar scheme");
}
JAR_PROVIDER = provider;
} finally {
Thread.currentThread().setContextClassLoader(ccl);
}
Expand Down

0 comments on commit b5beae1

Please sign in to comment.