Program: 29542
Project: 29542
Buggy source:
/** 
 * Method to read complete application and all defined descriptor for given app. Method is used to identify scope and validation for all defined jndi names at different namespace.
 * @param application
 * @return
 */
public boolean validateResourceDescriptor(Application application){
  CommonResourceBundleDescriptor commonResourceBundleDescriptor=(CommonResourceBundleDescriptor)application;
  Vector appLevel=new Vector();
  if (commonResourceBundleDescriptor != null) {
    Set<MailSessionDescriptor> mailSessionDescriptors=commonResourceBundleDescriptor.getMailSessionDescriptors();
    if (isExistingMailSession(mailSessionDescriptors,commonResourceBundleDescriptor.getName())) {
      return false;
    }
    Set<DataSourceDefinitionDescriptor> dataSourceDefinitionDescriptors=commonResourceBundleDescriptor.getDataSourceDefinitionDescriptors();
    if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,commonResourceBundleDescriptor.getName())) {
      return false;
    }
    if (mailSessionDescriptors.size() > 0 || dataSourceDefinitionDescriptors.size() > 0) {
      appLevel.add(commonResourceBundleDescriptor.getName());
    }
    validNameSpaceDetails.put(APP_KEYS,appLevel);
  }
  Set<ApplicationClientDescriptor> appClientDescs=application.getBundleDescriptors(ApplicationClientDescriptor.class);
  Vector appClientLevel=new Vector();
  for (  ApplicationClientDescriptor acd : appClientDescs) {
    Set<MailSessionDescriptor> mailSessionDescriptors=acd.getMailSessionDescriptors();
    if (isExistingMailSession(mailSessionDescriptors,acd.getName())) {
      return false;
    }
    Set<DataSourceDefinitionDescriptor> dataSourceDefinitionDescriptors=acd.getDataSourceDefinitionDescriptors();
    if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,acd.getName())) {
      return false;
    }
    if (mailSessionDescriptors.size() > 0 || dataSourceDefinitionDescriptors.size() > 0) {
      appClientLevel.add(acd.getName());
    }
  }
  validNameSpaceDetails.put(APPCLIENT_KEYS,appClientLevel);
  Set<ConnectorDescriptor> connectorDescs=application.getBundleDescriptors(ConnectorDescriptor.class);
  Vector cdLevel=new Vector();
  for (  ConnectorDescriptor cd : connectorDescs) {
    Set<MailSessionDescriptor> mailSessionDescriptors=cd.getMailSessionDescriptors();
    if (isExistingMailSession(mailSessionDescriptors,cd.getName())) {
      return false;
    }
    Set<DataSourceDefinitionDescriptor> dataSourceDefinitionDescriptors=cd.getDataSourceDefinitionDescriptors();
    if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,cd.getName())) {
      return false;
    }
    if (mailSessionDescriptors.size() > 0 || dataSourceDefinitionDescriptors.size() > 0) {
      cdLevel.add(cd.getName());
    }
  }
  validNameSpaceDetails.put(CONNECTOR_KEYS,cdLevel);
  Set<EjbBundleDescriptor> ejbBundleDescs=application.getBundleDescriptors(EjbBundleDescriptor.class);
  Vector ebdLevel=new Vector();
  Vector edLevel=new Vector();
  for (  EjbBundleDescriptor ebd : ejbBundleDescs) {
    Set<MailSessionDescriptor> mailSessionDescriptors=ebd.getMailSessionDescriptors();
    if (isExistingMailSession(mailSessionDescriptors,ebd.getName())) {
      return false;
    }
    Set<DataSourceDefinitionDescriptor> dataSourceDefinitionDescriptors=ebd.getDataSourceDefinitionDescriptors();
    if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,ebd.getName())) {
      return false;
    }
    if (mailSessionDescriptors.size() > 0 || dataSourceDefinitionDescriptors.size() > 0) {
      ebdLevel.add(ebd.getName());
    }
    Set<EjbDescriptor> ejbDescriptors=(Set<EjbDescriptor>)ebd.getEjbs();
    for (Iterator itr=ejbDescriptors.iterator(); itr.hasNext(); ) {
      EjbDescriptor ejbDescriptor=(EjbDescriptor)itr.next();
      mailSessionDescriptors=ejbDescriptor.getMailSessionDescriptors();
      if (isExistingMailSession(mailSessionDescriptors,ebd.getName() + "String_Node_Str" + ejbDescriptor.getName())) {
        return false;
      }
      dataSourceDefinitionDescriptors=ejbDescriptor.getDataSourceDefinitionDescriptors();
      if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,ebd.getName() + "String_Node_Str" + ejbDescriptor.getName())) {
        return false;
      }
      if (mailSessionDescriptors.size() > 0 || dataSourceDefinitionDescriptors.size() > 0) {
        edLevel.add(ebd.getName() + "String_Node_Str" + ejbDescriptor.getName());
      }
    }
  }
  validNameSpaceDetails.put(EJBBUNDLE_KEYS,ebdLevel);
  validNameSpaceDetails.put(EJB_KEYS,edLevel);
  Set<WebBundleDescriptor> webBundleDescs=application.getBundleDescriptors(WebBundleDescriptor.class);
  Vector wbdLevel=new Vector();
  for (  WebBundleDescriptor wbd : webBundleDescs) {
    Set<MailSessionDescriptor> mailSessionDescriptors=wbd.getMailSessionDescriptors();
    if (isExistingMailSession(mailSessionDescriptors,wbd.getName())) {
      return false;
    }
    Set<DataSourceDefinitionDescriptor> dataSourceDefinitionDescriptors=wbd.getDataSourceDefinitionDescriptors();
    if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,wbd.getName())) {
      return false;
    }
    if (mailSessionDescriptors.size() > 0 || dataSourceDefinitionDescriptors.size() > 0) {
      wbdLevel.add(wbd.getName());
    }
  }
  validNameSpaceDetails.put(WEBBUNDLE_KEYS,wbdLevel);
  if (allUniqueResource) {
    return compareDescriptors();
  }
  return allUniqueResource;
}

Fixed version (ground truth):
/** 
 * Method to read complete application and all defined descriptor for given app. Method is used to identify scope and validation for all defined jndi names at different namespace.
 * @param application
 * @return
 */
public boolean validateResourceDescriptor(Application application){
  final String APP_LEVEL="String_Node_Str";
  final String EJBBUNDLE_LEVEL="String_Node_Str";
  final String EJB_LEVEL="String_Node_Str";
  final String APPCLIENTBUNDLE_LEVEL="String_Node_Str";
  final String APPCLIENT_LEVEL="String_Node_Str";
  final String WEBBUNDLE_LEVEL="String_Node_Str";
  CommonResourceBundleDescriptor commonResourceBundleDescriptor=(CommonResourceBundleDescriptor)application;
  Vector appLevel=new Vector();
  if (commonResourceBundleDescriptor != null) {
    Set<MailSessionDescriptor> mailSessionDescriptors=commonResourceBundleDescriptor.getMailSessionDescriptors();
    if (isExistingMailSession(mailSessionDescriptors,APP_LEVEL + commonResourceBundleDescriptor.getName())) {
      return false;
    }
    Set<DataSourceDefinitionDescriptor> dataSourceDefinitionDescriptors=commonResourceBundleDescriptor.getDataSourceDefinitionDescriptors();
    if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,APP_LEVEL + commonResourceBundleDescriptor.getName())) {
      return false;
    }
    appLevel.add(APP_LEVEL + commonResourceBundleDescriptor.getName());
    validNameSpaceDetails.put(APP_KEYS,appLevel);
  }
  Set<ApplicationClientDescriptor> appClientDescs=application.getBundleDescriptors(ApplicationClientDescriptor.class);
  Vector appClientLevel=new Vector();
  for (  ApplicationClientDescriptor acd : appClientDescs) {
    Set<MailSessionDescriptor> mailSessionDescriptors=acd.getMailSessionDescriptors();
    if (isExistingMailSession(mailSessionDescriptors,APPCLIENTBUNDLE_LEVEL + acd.getName())) {
      return false;
    }
    Set<DataSourceDefinitionDescriptor> dataSourceDefinitionDescriptors=acd.getDataSourceDefinitionDescriptors();
    if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,APPCLIENTBUNDLE_LEVEL + acd.getName())) {
      return false;
    }
    appClientLevel.add(APPCLIENTBUNDLE_LEVEL + acd.getName());
  }
  validNameSpaceDetails.put(APPCLIENT_KEYS,appClientLevel);
  Set<ConnectorDescriptor> connectorDescs=application.getBundleDescriptors(ConnectorDescriptor.class);
  Vector cdLevel=new Vector();
  for (  ConnectorDescriptor cd : connectorDescs) {
    Set<MailSessionDescriptor> mailSessionDescriptors=cd.getMailSessionDescriptors();
    if (isExistingMailSession(mailSessionDescriptors,APPCLIENT_LEVEL + cd.getName())) {
      return false;
    }
    Set<DataSourceDefinitionDescriptor> dataSourceDefinitionDescriptors=cd.getDataSourceDefinitionDescriptors();
    if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,APPCLIENT_LEVEL + cd.getName())) {
      return false;
    }
    cdLevel.add(APPCLIENT_LEVEL + cd.getName());
  }
  validNameSpaceDetails.put(CONNECTOR_KEYS,cdLevel);
  Set<EjbBundleDescriptor> ejbBundleDescs=application.getBundleDescriptors(EjbBundleDescriptor.class);
  Vector ebdLevel=new Vector();
  Vector edLevel=new Vector();
  for (  EjbBundleDescriptor ebd : ejbBundleDescs) {
    Set<MailSessionDescriptor> mailSessionDescriptors=ebd.getMailSessionDescriptors();
    if (isExistingMailSession(mailSessionDescriptors,EJBBUNDLE_LEVEL + ebd.getName())) {
      return false;
    }
    Set<DataSourceDefinitionDescriptor> dataSourceDefinitionDescriptors=ebd.getDataSourceDefinitionDescriptors();
    if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,EJBBUNDLE_LEVEL + ebd.getName())) {
      return false;
    }
    ebdLevel.add(EJBBUNDLE_LEVEL + ebd.getName());
    Set<EjbDescriptor> ejbDescriptors=(Set<EjbDescriptor>)ebd.getEjbs();
    for (Iterator itr=ejbDescriptors.iterator(); itr.hasNext(); ) {
      EjbDescriptor ejbDescriptor=(EjbDescriptor)itr.next();
      mailSessionDescriptors=ejbDescriptor.getMailSessionDescriptors();
      if (isExistingMailSession(mailSessionDescriptors,EJB_LEVEL + ebd.getName() + "String_Node_Str"+ ejbDescriptor.getName())) {
        return false;
      }
      dataSourceDefinitionDescriptors=ejbDescriptor.getDataSourceDefinitionDescriptors();
      if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,EJB_LEVEL + ebd.getName() + "String_Node_Str"+ ejbDescriptor.getName())) {
        return false;
      }
      edLevel.add(EJB_LEVEL + ebd.getName() + "String_Node_Str"+ ejbDescriptor.getName());
    }
  }
  validNameSpaceDetails.put(EJBBUNDLE_KEYS,ebdLevel);
  validNameSpaceDetails.put(EJB_KEYS,edLevel);
  Set<WebBundleDescriptor> webBundleDescs=application.getBundleDescriptors(WebBundleDescriptor.class);
  Vector wbdLevel=new Vector();
  for (  WebBundleDescriptor wbd : webBundleDescs) {
    Set<MailSessionDescriptor> mailSessionDescriptors=wbd.getMailSessionDescriptors();
    if (isExistingMailSession(mailSessionDescriptors,WEBBUNDLE_LEVEL + wbd.getName())) {
      return false;
    }
    Set<DataSourceDefinitionDescriptor> dataSourceDefinitionDescriptors=wbd.getDataSourceDefinitionDescriptors();
    if (isExistingDataSourceDefinition(dataSourceDefinitionDescriptors,WEBBUNDLE_LEVEL + wbd.getName())) {
      return false;
    }
    wbdLevel.add(WEBBUNDLE_LEVEL + wbd.getName());
  }
  validNameSpaceDetails.put(WEBBUNDLE_KEYS,wbdLevel);
  if (allUniqueResource) {
    return compareDescriptors();
  }
  return allUniqueResource;
}