Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArC: prevent duplicate bean discovery & detect duplicate bean identifiers #37565

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,14 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
.map(StereotypeInfo::getName)
.collect(Collectors.toSet());

Set<DotName> seenClasses = new HashSet<>();

// If needed use the specialized immutable index to discover beans
for (ClassInfo beanClass : beanArchiveImmutableIndex.getKnownClasses()) {
if (!seenClasses.add(beanClass.name())) {
// avoid discovering the same bean twice
continue;
}

if (Modifier.isInterface(beanClass.flags()) || Modifier.isAbstract(beanClass.flags())
|| beanClass.isAnnotation() || beanClass.isEnum()) {
Expand Down Expand Up @@ -1583,6 +1589,29 @@ private void validateBeans(List<Throwable> errors, Consumer<BytecodeTransformer>
}
}
}

List<Map.Entry<String, List<BeanInfo>>> duplicateBeanIds = beans.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");
errors.add(new DeploymentException(error.toString()));
}
}

private void findNamespaces(BeanInfo bean, Set<String> namespaces) {
Expand Down
Loading