Skip to content

Commit

Permalink
ArC: detect duplicate bean identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed Dec 6, 2023
1 parent 903cd31 commit 6588f1a
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.stream.Collectors;

import jakarta.annotation.Priority;
import jakarta.enterprise.inject.spi.DeploymentException;

import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
Expand Down Expand Up @@ -185,6 +186,30 @@ public List<Resource> generateResources(ReflectionRegistration reflectionRegistr
ExecutorService executor)
throws IOException, InterruptedException, ExecutionException {

List<Map.Entry<String, List<BeanInfo>>> duplicateBeanIds = beanDeployment.getBeans()
.stream()
.collect(Collectors.groupingBy(BeanInfo::getIdentifier))
.entrySet()
.stream()
.filter(entry -> entry.getValue().size() > 1)
.collect(Collectors.toList());
if (!duplicateBeanIds.isEmpty()) {
String separator = "====================";
StringBuilder error = new StringBuilder("\n")
.append(separator).append(separator).append(separator).append(separator).append("\n")
.append("Multiple beans with the same identifier found!\n")
.append("----------------------------------------------\n")
.append("This is an internal error. Please report a bug and attach the following listing.\n\n");
for (Map.Entry<String, List<BeanInfo>> entry : duplicateBeanIds) {
error.append(entry.getKey()).append(" -> ").append(entry.getValue().size()).append(" beans:\n");
for (BeanInfo bean : entry.getValue()) {
error.append("- ").append(bean).append("\n");
}
}
error.append(separator).append(separator).append(separator).append(separator).append("\n");
throw new DeploymentException(error.toString());
}

ReflectionRegistration refReg = reflectionRegistration != null ? reflectionRegistration : this.reflectionRegistration;
PrivateMembersCollector privateMembers = new PrivateMembersCollector();

Expand Down

0 comments on commit 6588f1a

Please sign in to comment.