Program: 167697
Project: 167697
Buggy source:
@Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  final DeploymentUnit deploymentUnit=phaseContext.getDeploymentUnit();
  final ResourceRoot deploymentRoot=deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
  final ServiceModuleLoader moduleLoader=deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
  if (deploymentUnit.getParent() != null) {
    if (deploymentRoot.hasAttachment(SUB_DEPLOYMENT_STRUCTURE)) {
      final ModuleSpecification subModuleSpec=deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
      handleDeployment(phaseContext,deploymentUnit,subModuleSpec,deploymentRoot.getAttachment(SUB_DEPLOYMENT_STRUCTURE));
    }
  }
  VirtualFile deploymentFile=null;
  for (  final String loc : DEPLOYMENT_STRUCTURE_DESCRIPTOR_LOCATIONS) {
    final VirtualFile file=deploymentRoot.getRoot().getChild(loc);
    if (file.exists()) {
      deploymentFile=file;
      break;
    }
  }
  ParseResult result=deploymentUnit.getAttachment(RESULT_ATTACHMENT_KEY);
  if (deploymentFile == null && result == null) {
    return;
  }
  if (deploymentUnit.getParent() != null) {
    if (deploymentFile != null) {
      ServerLogger.DEPLOYMENT_LOGGER.jbossDeploymentStructureIgnored(deploymentFile.getPathName());
    }
    if (result != null) {
      ServerLogger.DEPLOYMENT_LOGGER.jbossDeploymentStructureNamespaceIgnored(deploymentUnit.getName());
    }
    return;
  }
  try {
    if (deploymentFile != null) {
      result=parse(deploymentFile.getPhysicalFile(),deploymentUnit,moduleLoader);
    }
    final ModuleSpecification moduleSpec=deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    if (result.getEarSubDeploymentsIsolated() != null) {
      moduleSpec.setSubDeploymentModulesIsolated(result.getEarSubDeploymentsIsolated());
    }
    if (result.getEarExclusionsCascadedToSubDeployments() != null) {
      moduleSpec.setExclusionsCascadedToSubDeployments(result.getEarExclusionsCascadedToSubDeployments());
    }
    final ModuleStructureSpec rootDeploymentSpecification=result.getRootDeploymentSpecification();
    if (rootDeploymentSpecification != null) {
      handleDeployment(phaseContext,deploymentUnit,moduleSpec,rootDeploymentSpecification);
    }
    final Map<String,ResourceRoot> subDeploymentMap=new HashMap<String,ResourceRoot>();
    final List<ResourceRoot> resourceRoots=deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
    for (    final ResourceRoot root : resourceRoots) {
      if (SubDeploymentMarker.isSubDeployment(root)) {
        subDeploymentMap.put(root.getRoot().getPathNameRelativeTo(deploymentRoot.getRoot()),root);
      }
    }
    for (    final Entry<String,ModuleStructureSpec> entry : result.getSubDeploymentSpecifications().entrySet()) {
      final String path=entry.getKey();
      final ModuleStructureSpec spec=entry.getValue();
      if (!subDeploymentMap.containsKey(path)) {
        throw subDeploymentNotFound(path,subDeploymentMap.keySet());
      }
      final ResourceRoot subDeployment=subDeploymentMap.get(path);
      subDeployment.putAttachment(SUB_DEPLOYMENT_STRUCTURE,spec);
      if (moduleSpec.isExclusionsCascadedToSubDeployments() && rootDeploymentSpecification != null) {
        for (        ModuleIdentifier exclusion : rootDeploymentSpecification.getExclusions()) {
          spec.getExclusions().add(exclusion);
        }
      }
    }
    for (    final ModuleStructureSpec additionalModule : result.getAdditionalModules()) {
      for (      final ModuleIdentifier identifier : additionalModule.getAnnotationModules()) {
        ServerLogger.DEPLOYMENT_LOGGER.annotationImportIgnored(identifier,additionalModule.getModuleIdentifier());
      }
      final List<ResourceRoot> additionalModuleResourceRoots=new ArrayList<ResourceRoot>(additionalModule.getResourceRoots());
      final ListIterator<ResourceRoot> itr=additionalModuleResourceRoots.listIterator();
      while (itr.hasNext()) {
        final ResourceRoot resourceRoot=itr.next();
        if (!resourceRoot.getRoot().exists()) {
          ServerLogger.DEPLOYMENT_LOGGER.additionalResourceRootDoesNotExist(resourceRoot.getRoot().getPathName());
          itr.remove();
        }
      }
      final AdditionalModuleSpecification additional=new AdditionalModuleSpecification(additionalModule.getModuleIdentifier(),additionalModuleResourceRoots);
      additional.addAliases(additionalModule.getAliases());
      additional.addSystemDependencies(additionalModule.getModuleDependencies());
      deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_MODULES,additional);
      for (      final ResourceRoot root : additionalModuleResourceRoots) {
        ResourceRootIndexer.indexResourceRoot(root);
      }
    }
  }
 catch (  IOException e) {
    throw new DeploymentUnitProcessingException(e);
  }
}

Fixed version (ground truth):
@Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  final DeploymentUnit deploymentUnit=phaseContext.getDeploymentUnit();
  final ResourceRoot deploymentRoot=deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
  final ServiceModuleLoader moduleLoader=deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
  if (deploymentUnit.getParent() != null) {
    if (deploymentRoot.hasAttachment(SUB_DEPLOYMENT_STRUCTURE)) {
      final ModuleSpecification subModuleSpec=deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
      Set<ModuleIdentifier> additionalModules=new HashSet<>();
      for (      AdditionalModuleSpecification i : deploymentUnit.getParent().getAttachmentList(Attachments.ADDITIONAL_MODULES)) {
        additionalModules.add(i.getModuleIdentifier());
      }
      handleDeployment(phaseContext,deploymentUnit,subModuleSpec,deploymentRoot.getAttachment(SUB_DEPLOYMENT_STRUCTURE),additionalModules);
    }
  }
  VirtualFile deploymentFile=null;
  for (  final String loc : DEPLOYMENT_STRUCTURE_DESCRIPTOR_LOCATIONS) {
    final VirtualFile file=deploymentRoot.getRoot().getChild(loc);
    if (file.exists()) {
      deploymentFile=file;
      break;
    }
  }
  ParseResult result=deploymentUnit.getAttachment(RESULT_ATTACHMENT_KEY);
  if (deploymentFile == null && result == null) {
    return;
  }
  if (deploymentUnit.getParent() != null) {
    if (deploymentFile != null) {
      ServerLogger.DEPLOYMENT_LOGGER.jbossDeploymentStructureIgnored(deploymentFile.getPathName());
    }
    if (result != null) {
      ServerLogger.DEPLOYMENT_LOGGER.jbossDeploymentStructureNamespaceIgnored(deploymentUnit.getName());
    }
    return;
  }
  try {
    if (deploymentFile != null) {
      result=parse(deploymentFile.getPhysicalFile(),deploymentUnit,moduleLoader);
    }
    Set<ModuleIdentifier> additionalModuleSet=new HashSet<>();
    for (    final ModuleStructureSpec additionalModule : result.getAdditionalModules()) {
      for (      final ModuleIdentifier identifier : additionalModule.getAnnotationModules()) {
        ServerLogger.DEPLOYMENT_LOGGER.annotationImportIgnored(identifier,additionalModule.getModuleIdentifier());
      }
      final List<ResourceRoot> additionalModuleResourceRoots=new ArrayList<ResourceRoot>(additionalModule.getResourceRoots());
      final ListIterator<ResourceRoot> itr=additionalModuleResourceRoots.listIterator();
      while (itr.hasNext()) {
        final ResourceRoot resourceRoot=itr.next();
        if (!resourceRoot.getRoot().exists()) {
          ServerLogger.DEPLOYMENT_LOGGER.additionalResourceRootDoesNotExist(resourceRoot.getRoot().getPathName());
          itr.remove();
        }
      }
      additionalModuleSet.add(additionalModule.getModuleIdentifier());
      final AdditionalModuleSpecification additional=new AdditionalModuleSpecification(additionalModule.getModuleIdentifier(),additionalModuleResourceRoots);
      additional.addAliases(additionalModule.getAliases());
      additional.addSystemDependencies(additionalModule.getModuleDependencies());
      deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_MODULES,additional);
      for (      final ResourceRoot root : additionalModuleResourceRoots) {
        ResourceRootIndexer.indexResourceRoot(root);
      }
    }
    final ModuleSpecification moduleSpec=deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    if (result.getEarSubDeploymentsIsolated() != null) {
      moduleSpec.setSubDeploymentModulesIsolated(result.getEarSubDeploymentsIsolated());
    }
    if (result.getEarExclusionsCascadedToSubDeployments() != null) {
      moduleSpec.setExclusionsCascadedToSubDeployments(result.getEarExclusionsCascadedToSubDeployments());
    }
    final ModuleStructureSpec rootDeploymentSpecification=result.getRootDeploymentSpecification();
    if (rootDeploymentSpecification != null) {
      handleDeployment(phaseContext,deploymentUnit,moduleSpec,rootDeploymentSpecification,additionalModuleSet);
    }
    final Map<String,ResourceRoot> subDeploymentMap=new HashMap<String,ResourceRoot>();
    final List<ResourceRoot> resourceRoots=deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
    for (    final ResourceRoot root : resourceRoots) {
      if (SubDeploymentMarker.isSubDeployment(root)) {
        subDeploymentMap.put(root.getRoot().getPathNameRelativeTo(deploymentRoot.getRoot()),root);
      }
    }
    for (    final Entry<String,ModuleStructureSpec> entry : result.getSubDeploymentSpecifications().entrySet()) {
      final String path=entry.getKey();
      final ModuleStructureSpec spec=entry.getValue();
      if (!subDeploymentMap.containsKey(path)) {
        throw subDeploymentNotFound(path,subDeploymentMap.keySet());
      }
      final ResourceRoot subDeployment=subDeploymentMap.get(path);
      subDeployment.putAttachment(SUB_DEPLOYMENT_STRUCTURE,spec);
      if (moduleSpec.isExclusionsCascadedToSubDeployments() && rootDeploymentSpecification != null) {
        for (        ModuleIdentifier exclusion : rootDeploymentSpecification.getExclusions()) {
          spec.getExclusions().add(exclusion);
        }
      }
    }
  }
 catch (  IOException e) {
    throw new DeploymentUnitProcessingException(e);
  }
}