Program: 29417
Project: 29417
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){
  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);
  }
  if (application != null) {
    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);
  }
  if (application != null) {
    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);
  }
  if (application != null) {
    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);
  }
  if (application != null) {
    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;
}

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;
    }
    Set<ConnectorResourceDefinitionDescriptor> connectorResourceDefinitionDescriptors=application.getConnectorResourceDefinitionDescriptors();
    if (isExistingConnectorResourceDefinitionDescriptor(connectorResourceDefinitionDescriptors,APP_LEVEL + application.getName())) {
      return false;
    }
    appLevel.add(APP_LEVEL + commonResourceBundleDescriptor.getName());
    validNameSpaceDetails.put(APP_KEYS,appLevel);
  }
  if (application != null) {
    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);
  }
  if (application != null) {
    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;
      }
      Set<ConnectorResourceDefinitionDescriptor> connectorResourceDefinitionDescriptors=cd.getConnectorResourceDefinitionDescriptors();
      if (isExistingConnectorResourceDefinitionDescriptor(connectorResourceDefinitionDescriptors,APPCLIENT_LEVEL + cd.getName())) {
        return false;
      }
      cdLevel.add(APPCLIENT_LEVEL + cd.getName());
    }
    validNameSpaceDetails.put(CONNECTOR_KEYS,cdLevel);
  }
  if (application != null) {
    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;
      }
      Set<ConnectorResourceDefinitionDescriptor> connectorResourceDefinitionDescriptors=ebd.getConnectorResourceDefinitionDescriptors();
      if (isExistingConnectorResourceDefinitionDescriptor(connectorResourceDefinitionDescriptors,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;
        }
        connectorResourceDefinitionDescriptors=ejbDescriptor.getConnectorResourceDefinitionDescriptors();
        if (isExistingConnectorResourceDefinitionDescriptor(connectorResourceDefinitionDescriptors,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);
  }
  if (application != null) {
    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;
      }
      Set<ConnectorResourceDefinitionDescriptor> connectorResourceDefinitionDescriptors=wbd.getConnectorResourceDefinitionDescriptors();
      if (isExistingConnectorResourceDefinitionDescriptor(connectorResourceDefinitionDescriptors,WEBBUNDLE_LEVEL + wbd.getName())) {
        return false;
      }
      wbdLevel.add(WEBBUNDLE_LEVEL + wbd.getName());
    }
    validNameSpaceDetails.put(WEBBUNDLE_KEYS,wbdLevel);
  }
  if (allUniqueResource) {
    return compareDescriptors();
  }
  return allUniqueResource;
}