Program: 30175
Project: 30175
Buggy source:
/** 
 * read the modules deployment descriptor from this application object using the passed archive
 * @param app application containing the list of modules.
 * @param appArchive containing the sub modules files.
 * @return true if everything went fine
 */
public boolean readModulesDescriptors(Application app,ReadableArchive appArchive) throws IOException, SAXParseException {
  List<ModuleDescriptor> nonexistentModules=new ArrayList<ModuleDescriptor>();
  for (  ModuleDescriptor aModule : app.getModules()) {
    if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
      DOLUtils.getDefaultLogger().fine("String_Node_Str" + aModule);
    }
    RootDeploymentDescriptor descriptor=null;
    Archivist newArchivist=archivistFactory.get().getPrivateArchivistFor(aModule.getModuleType());
    newArchivist.initializeContext(this);
    newArchivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation());
    newArchivist.setRuntimeXMLValidationLevel(this.getRuntimeXMLValidationLevel());
    newArchivist.setAnnotationProcessingRequested(annotationProcessingRequested);
    ReadableArchive embeddedArchive=appArchive.getSubArchive(aModule.getArchiveUri());
    if (embeddedArchive != null) {
      embeddedArchive.setParentArchive(appArchive);
    }
    if (aModule.getAlternateDescriptor() != null) {
      InputStream is=appArchive.getEntry(aModule.getAlternateDescriptor());
      DeploymentDescriptorFile ddFile=newArchivist.getStandardDDFile();
      ddFile.setXMLValidation(newArchivist.getXMLValidation());
      ddFile.setXMLValidationLevel(newArchivist.getXMLValidationLevel());
      if (appArchive.getURI() != null) {
        ddFile.setErrorReportingString(appArchive.getURI().getSchemeSpecificPart());
      }
      descriptor=(BundleDescriptor)ddFile.read(is);
      ((BundleDescriptor)descriptor).setApplication(app);
      is.close();
      Map<ExtensionsArchivist,RootDeploymentDescriptor> extensions=new HashMap<ExtensionsArchivist,RootDeploymentDescriptor>();
      if (extensionsArchivists != null) {
        for (        ExtensionsArchivist extension : extensionsArchivists) {
          if (extension.supportsModuleType(aModule.getModuleType())) {
            Object rdd=extension.open(newArchivist,embeddedArchive,descriptor);
            if (rdd instanceof RootDeploymentDescriptor) {
              extensions.put(extension,(RootDeploymentDescriptor)rdd);
            }
          }
        }
      }
      newArchivist.postStandardDDsRead(descriptor,embeddedArchive,extensions);
      newArchivist.readAnnotations(embeddedArchive,descriptor,extensions);
      newArchivist.postAnnotationProcess(descriptor,embeddedArchive);
      newArchivist.postOpen(descriptor,embeddedArchive);
      if (isHandlingRuntimeInfo()) {
        is=appArchive.getEntry("String_Node_Str" + aModule.getAlternateDescriptor());
        if (is != null) {
          DeploymentDescriptorFile confDD=newArchivist.getConfigurationDDFile();
          confDD.setXMLValidation(newArchivist.getRuntimeXMLValidation());
          confDD.setXMLValidationLevel(newArchivist.getRuntimeXMLValidationLevel());
          if (appArchive.getURI() != null) {
            confDD.setErrorReportingString(appArchive.getURI().getSchemeSpecificPart());
          }
          confDD.read(descriptor,is);
          is.close();
          newArchivist.postRuntimeDDsRead((RootDeploymentDescriptor)descriptor,embeddedArchive);
        }
 else {
          if (embeddedArchive != null) {
            newArchivist.readRuntimeDeploymentDescriptor(embeddedArchive,descriptor);
          }
        }
        for (        Map.Entry<ExtensionsArchivist,RootDeploymentDescriptor> extension : extensions.entrySet()) {
          if (extension.getValue() != null) {
            extension.getKey().readRuntimeDeploymentDescriptor(newArchivist,embeddedArchive,extension.getValue());
          }
        }
      }
    }
 else {
      if (embeddedArchive != null) {
        descriptor=newArchivist.open(embeddedArchive,app);
      }
 else {
        DOLUtils.getDefaultLogger().info(localStrings.getLocalString("String_Node_Str","String_Node_Str",new Object[]{aModule.getArchiveUri()}));
        nonexistentModules.add(aModule);
        continue;
      }
    }
    if (embeddedArchive != null) {
      embeddedArchive.close();
    }
    if (descriptor != null && descriptor instanceof BundleDescriptor) {
      descriptor.getModuleDescriptor().setArchiveUri(aModule.getArchiveUri());
      aModule.setModuleName(descriptor.getModuleDescriptor().getModuleName());
      aModule.setDescriptor((BundleDescriptor)descriptor);
      ((BundleDescriptor)descriptor).setApplication(app);
      aModule.setManifest(newArchivist.getManifest());
      if (!appArchive.exists("String_Node_Str")) {
        if (aModule.getModuleType().equals(XModuleType.WAR)) {
          aModule.setContextRoot(aModule.getModuleName());
        }
      }
    }
 else {
      if (embeddedArchive != null) {
        DOLUtils.getDefaultLogger().info(localStrings.getLocalString("String_Node_Str","String_Node_Str",new Object[]{aModule.getArchiveUri()}));
      }
      return false;
    }
  }
  for (  ModuleDescriptor nonexistentModule : nonexistentModules) {
    app.removeModule(nonexistentModule);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * read the modules deployment descriptor from this application object using the passed archive
 * @param app application containing the list of modules.
 * @param appArchive containing the sub modules files.
 * @return true if everything went fine
 */
public boolean readModulesDescriptors(Application app,ReadableArchive appArchive) throws IOException, SAXParseException {
  List<ModuleDescriptor> nonexistentModules=new ArrayList<ModuleDescriptor>();
  for (  ModuleDescriptor aModule : app.getModules()) {
    if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
      DOLUtils.getDefaultLogger().fine("String_Node_Str" + aModule);
    }
    RootDeploymentDescriptor descriptor=null;
    Archivist newArchivist=archivistFactory.get().getPrivateArchivistFor(aModule.getModuleType());
    newArchivist.initializeContext(this);
    newArchivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation());
    newArchivist.setRuntimeXMLValidationLevel(this.getRuntimeXMLValidationLevel());
    newArchivist.setAnnotationProcessingRequested(annotationProcessingRequested);
    ReadableArchive embeddedArchive=appArchive.getSubArchive(aModule.getArchiveUri());
    if (embeddedArchive == null) {
      throw new IllegalArgumentException(localStrings.getLocalString("String_Node_Str","String_Node_Str",new Object[]{aModule.getArchiveUri()}));
    }
    embeddedArchive.setParentArchive(appArchive);
    if (aModule.getAlternateDescriptor() != null) {
      InputStream is=appArchive.getEntry(aModule.getAlternateDescriptor());
      DeploymentDescriptorFile ddFile=newArchivist.getStandardDDFile();
      ddFile.setXMLValidation(newArchivist.getXMLValidation());
      ddFile.setXMLValidationLevel(newArchivist.getXMLValidationLevel());
      if (appArchive.getURI() != null) {
        ddFile.setErrorReportingString(appArchive.getURI().getSchemeSpecificPart());
      }
      descriptor=(BundleDescriptor)ddFile.read(is);
      ((BundleDescriptor)descriptor).setApplication(app);
      is.close();
      Map<ExtensionsArchivist,RootDeploymentDescriptor> extensions=new HashMap<ExtensionsArchivist,RootDeploymentDescriptor>();
      if (extensionsArchivists != null) {
        for (        ExtensionsArchivist extension : extensionsArchivists) {
          if (extension.supportsModuleType(aModule.getModuleType())) {
            Object rdd=extension.open(newArchivist,embeddedArchive,descriptor);
            if (rdd instanceof RootDeploymentDescriptor) {
              extensions.put(extension,(RootDeploymentDescriptor)rdd);
            }
          }
        }
      }
      newArchivist.postStandardDDsRead(descriptor,embeddedArchive,extensions);
      newArchivist.readAnnotations(embeddedArchive,descriptor,extensions);
      newArchivist.postAnnotationProcess(descriptor,embeddedArchive);
      newArchivist.postOpen(descriptor,embeddedArchive);
      if (isHandlingRuntimeInfo()) {
        is=appArchive.getEntry("String_Node_Str" + aModule.getAlternateDescriptor());
        if (is != null) {
          DeploymentDescriptorFile confDD=newArchivist.getConfigurationDDFile();
          confDD.setXMLValidation(newArchivist.getRuntimeXMLValidation());
          confDD.setXMLValidationLevel(newArchivist.getRuntimeXMLValidationLevel());
          if (appArchive.getURI() != null) {
            confDD.setErrorReportingString(appArchive.getURI().getSchemeSpecificPart());
          }
          confDD.read(descriptor,is);
          is.close();
          newArchivist.postRuntimeDDsRead((RootDeploymentDescriptor)descriptor,embeddedArchive);
        }
 else {
          if (embeddedArchive != null) {
            newArchivist.readRuntimeDeploymentDescriptor(embeddedArchive,descriptor);
          }
        }
        for (        Map.Entry<ExtensionsArchivist,RootDeploymentDescriptor> extension : extensions.entrySet()) {
          if (extension.getValue() != null) {
            extension.getKey().readRuntimeDeploymentDescriptor(newArchivist,embeddedArchive,extension.getValue());
          }
        }
      }
    }
 else {
      if (embeddedArchive != null) {
        descriptor=newArchivist.open(embeddedArchive,app);
      }
 else {
        DOLUtils.getDefaultLogger().info(localStrings.getLocalString("String_Node_Str","String_Node_Str",new Object[]{aModule.getArchiveUri()}));
        nonexistentModules.add(aModule);
        continue;
      }
    }
    if (embeddedArchive != null) {
      embeddedArchive.close();
    }
    if (descriptor != null && descriptor instanceof BundleDescriptor) {
      descriptor.getModuleDescriptor().setArchiveUri(aModule.getArchiveUri());
      aModule.setModuleName(descriptor.getModuleDescriptor().getModuleName());
      aModule.setDescriptor((BundleDescriptor)descriptor);
      ((BundleDescriptor)descriptor).setApplication(app);
      aModule.setManifest(newArchivist.getManifest());
      if (!appArchive.exists("String_Node_Str")) {
        if (aModule.getModuleType().equals(XModuleType.WAR)) {
          aModule.setContextRoot(aModule.getModuleName());
        }
      }
    }
 else {
      if (embeddedArchive != null) {
        DOLUtils.getDefaultLogger().info(localStrings.getLocalString("String_Node_Str","String_Node_Str",new Object[]{aModule.getArchiveUri()}));
      }
      return false;
    }
  }
  for (  ModuleDescriptor nonexistentModule : nonexistentModules) {
    app.removeModule(nonexistentModule);
  }
  return true;
}