diff --git a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/RunnerClassLoader.java b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/RunnerClassLoader.java index 02c7c100e23c2..d02b6cf0a8dfc 100644 --- a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/RunnerClassLoader.java +++ b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/RunnerClassLoader.java @@ -32,7 +32,8 @@ public final class RunnerClassLoader extends ClassLoader { private final Set nonExistentResources; // the following two fields go hand in hand - they need to both be populated from the same data // in order for the resource loading to work properly - private final Set fullyIndexedDirectories; + // normally this field would be a set, but it only contains 2 elements, so making it a list is actually better + private final List fullyIndexedDirectories; private final Map directlyIndexedResourcesIndexMap; //Mutations protected by synchronization on the field value itself: @@ -42,7 +43,7 @@ public final class RunnerClassLoader extends ClassLoader { RunnerClassLoader(ClassLoader parent, Map resourceDirectoryMap, Set parentFirstPackages, Set nonExistentResources, - Set fullyIndexedDirectories, Map directlyIndexedResourcesIndexMap) { + List fullyIndexedDirectories, Map directlyIndexedResourcesIndexMap) { super(parent); this.resourceDirectoryMap = resourceDirectoryMap; this.parentFirstPackages = parentFirstPackages; diff --git a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java index b3e8b88bdc60a..a838802f51db3 100644 --- a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java +++ b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java @@ -11,7 +11,6 @@ import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; @@ -20,7 +19,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.BiConsumer; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; @@ -36,7 +34,7 @@ public class SerializedApplication { public static final String META_INF_VERSIONS = "META-INF/versions/"; // the files immediately (i.e. not recursively) under these paths should all be indexed - private static final Set FULLY_INDEXED_PATHS = new LinkedHashSet<>(Arrays.asList("", "META-INF/services")); + private static final List FULLY_INDEXED_PATHS = List.of("", "META-INF/services"); private static final int MAGIC = 0XF0315432; private static final int VERSION = 2; @@ -210,7 +208,8 @@ private static List writeJar(DataOutputStream out, Path jar) throws IOEx if (!entry.getName().contains("/")) { hasDefaultPackage = true; if (!entry.getName().isEmpty() && FULLY_INDEXED_PATHS.contains("")) { - fullyIndexedPaths.computeIfAbsent("", s -> new ArrayList<>(10)).add(entry.getName()); + fullyIndexedPaths.computeIfAbsent("", SerializedApplication::newFullyIndexedPathsValue) + .add(entry.getName()); } } else if (!entry.isDirectory()) { //some jars don't have correct directory entries @@ -222,7 +221,7 @@ private static List writeJar(DataOutputStream out, Path jar) throws IOEx if (entry.getName().startsWith(META_INF_VERSIONS)) { //multi release jar //we add all packages here - //they may no be relevant for some versions, but that is fine + //they may not be relevant for some versions, but that is fine String part = entry.getName().substring(META_INF_VERSIONS.length()); int slash = part.indexOf("/"); if (slash != -1) { @@ -233,12 +232,14 @@ private static List writeJar(DataOutputStream out, Path jar) throws IOEx } } - for (String path : FULLY_INDEXED_PATHS) { + for (int i = 0; i < FULLY_INDEXED_PATHS.size(); i++) { + String path = FULLY_INDEXED_PATHS.get(i); if (path.isEmpty()) { continue; } if (entry.getName().startsWith(path)) { - fullyIndexedPaths.computeIfAbsent(path, s -> new ArrayList<>(10)).add(entry.getName()); + fullyIndexedPaths.computeIfAbsent(path, SerializedApplication::newFullyIndexedPathsValue) + .add(entry.getName()); } } } @@ -258,6 +259,10 @@ private static List writeJar(DataOutputStream out, Path jar) throws IOEx } } + private static List newFullyIndexedPathsValue(String ignored) { + return new ArrayList<>(10); + } + private static void collectPackages(Path jar, Set dirs) throws IOException { if (Files.isDirectory(jar)) { //this can only really happen when testing quarkus itself @@ -356,14 +361,13 @@ void addResourceDir(String dir, JarResource resource) { } Map getResult() { - overrides.forEach(new BiConsumer>() { - @Override - public void accept(String dir, Set jarResources) { - result.put(dir, jarResources.toArray(EMPTY_ARRAY)); - } - }); + overrides.forEach(this::addToResult); return result; } + + private void addToResult(String dir, Set jarResources) { + result.put(dir, jarResources.toArray(EMPTY_ARRAY)); + } } }