From 5abb01204787d2d1e219843f20e13a6162926730 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 13 May 2022 11:50:49 +0300 Subject: [PATCH] Get rid of a lambda in Arc runtime code These are causing NoSuchMethodError on application startup (this can be verified easily either via the debugger, or from JFR events - see https://bugs.openjdk.java.net/browse/JDK-8161588 for more details about why the error occurs) which can have a small impact on startup performance N.B. I only replaced the code for the instances that were causing the issue at the startup of a Quarkus application --- .../java/io/quarkus/arc/impl/Instances.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Instances.java b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Instances.java index 047da5923fac4..6e75c4e3ed288 100644 --- a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Instances.java +++ b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Instances.java @@ -11,9 +11,7 @@ import java.util.Comparator; import java.util.List; import java.util.Set; -import java.util.function.Predicate; import java.util.function.Supplier; -import java.util.stream.Collectors; import javax.enterprise.context.Dependent; import javax.enterprise.inject.spi.InjectionPoint; @@ -21,8 +19,12 @@ public final class Instances { static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[] {}; - static final Comparator> PRIORITY_COMPARATOR = Collections - .reverseOrder(Comparator.comparingInt(InjectableBean::getPriority)); + static final Comparator> PRIORITY_COMPARATOR = new Comparator<>() { + @Override + public int compare(InjectableBean ib1, InjectableBean ib2) { + return Integer.compare(ib2.getPriority(), ib1.getPriority()); + } + }; private Instances() { } @@ -32,12 +34,16 @@ public static List> resolveBeans(Type requiredType, Set> resolveBeans(Type requiredType, Annotation... requiredQualifiers) { - return ArcContainerImpl.instance() - .getResolvedBeans(requiredType, requiredQualifiers) - .stream() - .filter(Predicate.not(InjectableBean::isSuppressed)) - .sorted(PRIORITY_COMPARATOR) - .collect(Collectors.toUnmodifiableList()); + Set> resolvedBeans = ArcContainerImpl.instance() + .getResolvedBeans(requiredType, requiredQualifiers); + List> nonSuppressed = new ArrayList<>(resolvedBeans.size()); + for (InjectableBean injectableBean : resolvedBeans) { + if (!injectableBean.isSuppressed()) { + nonSuppressed.add(injectableBean); + } + } + nonSuppressed.sort(PRIORITY_COMPARATOR); + return List.copyOf(nonSuppressed); } @SuppressWarnings("unchecked")