Skip to content

Commit

Permalink
Get rid of a lambda in Arc runtime code
Browse files Browse the repository at this point in the history
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
  • Loading branch information
geoand committed May 13, 2022
1 parent c34043b commit 8f15a1f
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
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;

public final class Instances {

static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[] {};

static final Comparator<InjectableBean<?>> PRIORITY_COMPARATOR = Collections
.reverseOrder(Comparator.comparingInt(InjectableBean::getPriority));
static final Comparator<InjectableBean<?>> PRIORITY_COMPARATOR = new Comparator<>() {
@Override
public int compare(InjectableBean<?> ib1, InjectableBean<?> ib2) {
return Integer.compare(ib2.getPriority(), ib1.getPriority());
}
};

private Instances() {
}
Expand All @@ -32,12 +34,16 @@ public static List<InjectableBean<?>> resolveBeans(Type requiredType, Set<Annota
}

public static List<InjectableBean<?>> resolveBeans(Type requiredType, Annotation... requiredQualifiers) {
return ArcContainerImpl.instance()
.getResolvedBeans(requiredType, requiredQualifiers)
.stream()
.filter(Predicate.not(InjectableBean::isSuppressed))
.sorted(PRIORITY_COMPARATOR)
.collect(Collectors.toUnmodifiableList());
Set<InjectableBean<?>> resolvedBeans = ArcContainerImpl.instance()
.getResolvedBeans(requiredType, requiredQualifiers);
List<InjectableBean<?>> nonSuppressed = new ArrayList<>(resolvedBeans.size());
for (InjectableBean<?> injectableBean : resolvedBeans) {
if (!injectableBean.isSuppressed()) {
nonSuppressed.add(injectableBean);
}
}
nonSuppressed.sort(PRIORITY_COMPARATOR);
return Collections.unmodifiableList(nonSuppressed);
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 8f15a1f

Please sign in to comment.