Skip to content

Commit

Permalink
bugfix: added removeDuplicateBeanClassNames() to fix MP-CDK issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lprimak committed Feb 26, 2025
1 parent c9e34f4 commit 52b79c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class BeanDeploymentArchiveImpl implements BeanDeploymentArchive, Seriali

private transient ReadableArchive archive;
private final String id;
private final List<String> moduleClassNames; // Names of classes in the module
final List<String> moduleClassNames; // Names of classes in the module
private final List<String> beanClassNames; // Names of bean classes in the module
private transient List<Class<?>> moduleClasses; // Classes in the module
private transient List<Class<?>> beanClasses; // Classes identified as Beans through Weld SPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ private void processApplicationLoaded(ApplicationInfo applicationInfo) {
try {
DeploymentImpl filtered = deploymentImpl.filter(rootBDA, applicationInfo);
completeDeployment(filtered);
removeDuplicateBeanClassNames(filtered);
WeldBootstrap bootstrap = filtered.context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class);
startWeldBootstrap(applicationInfo, rootBDA, bootstrap, filtered, componentInvocation);
} finally {
Expand All @@ -530,6 +531,7 @@ private void processApplicationLoaded(ApplicationInfo applicationInfo) {
}
} else if (!deploymentImpl.getRootBDAs().isEmpty()) {
completeDeployment(deploymentImpl);
removeDuplicateBeanClassNames(deploymentImpl);
// Legacy EJB-Jar scenario, one Weld instance per EAR
RootBeanDeploymentArchive bda = deploymentImpl.getRootBDAs().iterator().next();
WeldBootstrap bootstrap = unifyBootstrap(bda, applicationInfo);
Expand All @@ -556,6 +558,21 @@ private void processApplicationLoaded(ApplicationInfo applicationInfo) {
}
}

private static void removeDuplicateBeanClassNames(DeploymentImpl deploymentImpl) {
Set<String> allModuleClassNames = new HashSet<>();
for (BeanDeploymentArchive bda : deploymentImpl.getBeanDeploymentArchives()) {
if (bda instanceof BeanDeploymentArchiveImpl) {
BeanDeploymentArchiveImpl bdaImpl = (BeanDeploymentArchiveImpl) bda;
for (int ii = 0; ii < bdaImpl.moduleClassNames.size(); ii++) {
if (!allModuleClassNames.add(bdaImpl.moduleClassNames.get(ii))) {
bdaImpl.moduleClassNames.remove(ii);
--ii;
}
}
}
}
}

private void completeDeployment(DeploymentImpl deploymentImpl) {
deploymentImpl.buildDeploymentGraph();

Expand Down

0 comments on commit 52b79c5

Please sign in to comment.