Program: 28411
Project: 28411
Buggy source:
/** 
 * write the descriptor class to a DOM tree and return it
 * @param parent node for the DOM tree
 * @param webBundleDesc descriptor to write
 * @return the DOM tree top node
 */
public Node writeDescriptor(Node parent,T webBundleDesc){
  Node jarNode=super.writeDescriptor(parent,webBundleDesc);
  if (webBundleDesc.isDistributable()) {
    appendChild(jarNode,WebTagNames.DISTRIBUTABLE);
  }
  addInitParam(jarNode,WebTagNames.CONTEXT_PARAM,webBundleDesc.getContextParametersSet());
  FilterNode filterNode=new FilterNode();
  for (Enumeration filters=webBundleDesc.getServletFilters().elements(); filters.hasMoreElements(); ) {
    filterNode.writeDescriptor(jarNode,WebTagNames.FILTER,(ServletFilterDescriptor)filters.nextElement());
  }
  FilterMappingNode filterMappingNode=new FilterMappingNode();
  for (Enumeration mappings=webBundleDesc.getServletFilterMappings().elements(); mappings.hasMoreElements(); ) {
    filterMappingNode.writeDescriptor(jarNode,WebTagNames.FILTER_MAPPING,(ServletFilterMappingDescriptor)mappings.nextElement());
  }
  Vector appListeners=webBundleDesc.getAppListenerDescriptors();
  if (appListeners != null && !appListeners.isEmpty()) {
    ListenerNode listenerNode=new ListenerNode();
    for (Enumeration e=appListeners.elements(); e.hasMoreElements(); ) {
      listenerNode.writeDescriptor(jarNode,WebTagNames.LISTENER,(AppListenerDescriptorImpl)e.nextElement());
    }
  }
  Set servlets=webBundleDesc.getWebComponentDescriptors();
  if (servlets != null && !servlets.isEmpty()) {
    ServletNode servletNode=new ServletNode();
    for (Iterator e=servlets.iterator(); e.hasNext(); ) {
      WebComponentDescriptor aServlet=(WebComponentDescriptor)e.next();
      servletNode.writeDescriptor(jarNode,aServlet);
    }
    for (Iterator servletsIterator=servlets.iterator(); servletsIterator.hasNext(); ) {
      WebComponentDescriptor aServlet=(WebComponentDescriptor)servletsIterator.next();
      for (Iterator patterns=aServlet.getUrlPatternsSet().iterator(); patterns.hasNext(); ) {
        String pattern=(String)patterns.next();
        Node mappingNode=appendChild(jarNode,WebTagNames.SERVLET_MAPPING);
        appendTextChild(mappingNode,WebTagNames.SERVLET_NAME,aServlet.getCanonicalName());
        if (webBundleDesc.getSpecVersion().equals("String_Node_Str")) {
          if (!pattern.startsWith("String_Node_Str") && !pattern.startsWith("String_Node_Str")) {
            pattern="String_Node_Str" + pattern;
          }
        }
        appendTextChild(mappingNode,WebTagNames.URL_PATTERN,pattern);
      }
    }
  }
  MimeMappingNode mimeNode=new MimeMappingNode();
  for (Enumeration e=webBundleDesc.getMimeMappings(); e.hasMoreElements(); ) {
    MimeMappingDescriptor mimeMapping=(MimeMappingDescriptor)e.nextElement();
    mimeNode.writeDescriptor(jarNode,WebTagNames.MIME_MAPPING,mimeMapping);
  }
  Enumeration welcomeFiles=webBundleDesc.getWelcomeFiles();
  if (welcomeFiles.hasMoreElements()) {
    Node welcomeList=appendChild(jarNode,WebTagNames.WELCOME_FILE_LIST);
    while (welcomeFiles.hasMoreElements()) {
      appendTextChild(welcomeList,WebTagNames.WELCOME_FILE,(String)welcomeFiles.nextElement());
    }
  }
  Enumeration errorPages=webBundleDesc.getErrorPageDescriptors();
  if (errorPages.hasMoreElements()) {
    ErrorPageNode errorPageNode=new ErrorPageNode();
    while (errorPages.hasMoreElements()) {
      errorPageNode.writeDescriptor(jarNode,WebTagNames.ERROR_PAGE,(ErrorPageDescriptor)errorPages.nextElement());
    }
  }
  JspConfigDescriptorImpl jspConf=webBundleDesc.getJspConfigDescriptor();
  if (jspConf != null) {
    JspConfigNode ln=new JspConfigNode();
    ln.writeDescriptor(jarNode,WebTagNames.JSPCONFIG,jspConf);
  }
  Enumeration securityConstraints=webBundleDesc.getSecurityConstraints();
  if (securityConstraints.hasMoreElements()) {
    SecurityConstraintNode scNode=new SecurityConstraintNode();
    while (securityConstraints.hasMoreElements()) {
      SecurityConstraintImpl sc=(SecurityConstraintImpl)securityConstraints.nextElement();
      scNode.writeDescriptor(jarNode,WebTagNames.SECURITY_CONSTRAINT,sc);
    }
  }
  LoginConfigurationImpl lci=(LoginConfigurationImpl)webBundleDesc.getLoginConfiguration();
  if (lci != null) {
    LoginConfigNode lcn=new LoginConfigNode();
    lcn.writeDescriptor(jarNode,WebTagNames.LOGIN_CONFIG,lci);
  }
  Enumeration roles=webBundleDesc.getSecurityRoles();
  if (roles.hasMoreElements()) {
    SecurityRoleNode srNode=new SecurityRoleNode();
    while (roles.hasMoreElements()) {
      SecurityRoleDescriptor role=(SecurityRoleDescriptor)roles.nextElement();
      srNode.writeDescriptor(jarNode,WebTagNames.ROLE,role);
    }
  }
  writeEnvEntryDescriptors(jarNode,webBundleDesc.getEnvironmentProperties().iterator());
  writeEjbReferenceDescriptors(jarNode,webBundleDesc.getEjbReferenceDescriptors().iterator());
  writeServiceReferenceDescriptors(jarNode,webBundleDesc.getServiceReferenceDescriptors().iterator());
  writeResourceRefDescriptors(jarNode,webBundleDesc.getResourceReferenceDescriptors().iterator());
  writeResourceEnvRefDescriptors(jarNode,webBundleDesc.getResourceEnvReferenceDescriptors().iterator());
  writeMessageDestinationRefDescriptors(jarNode,webBundleDesc.getMessageDestinationReferenceDescriptors().iterator());
  writeEntityManagerReferenceDescriptors(jarNode,webBundleDesc.getEntityManagerReferenceDescriptors().iterator());
  writeEntityManagerFactoryReferenceDescriptors(jarNode,webBundleDesc.getEntityManagerFactoryReferenceDescriptors().iterator());
  writeLifeCycleCallbackDescriptors(jarNode,TagNames.POST_CONSTRUCT,webBundleDesc.getPostConstructDescriptors());
  writeLifeCycleCallbackDescriptors(jarNode,TagNames.PRE_DESTROY,webBundleDesc.getPreDestroyDescriptors());
  writeResourceDescriptors(jarNode,webBundleDesc.getAllResourcesDescriptors().iterator());
  writeMessageDestinations(jarNode,webBundleDesc.getMessageDestinations().iterator());
  LocaleEncodingMappingListDescriptor lemDesc=webBundleDesc.getLocaleEncodingMappingListDescriptor();
  if (lemDesc != null) {
    LocaleEncodingMappingListNode ln=new LocaleEncodingMappingListNode();
    ln.writeDescriptor(jarNode,WebTagNames.LOCALE_ENCODING_MAPPING_LIST,lemDesc);
  }
  if (webBundleDesc.getSessionConfig() != null) {
    SessionConfigNode scNode=new SessionConfigNode();
    scNode.writeDescriptor(jarNode,WebTagNames.SESSION_CONFIG,(SessionConfigDescriptor)webBundleDesc.getSessionConfig());
  }
  return jarNode;
}

Fixed version (ground truth):
/** 
 * write the descriptor class to a DOM tree and return it
 * @param parent node for the DOM tree
 * @param webBundleDesc descriptor to write
 * @return the DOM tree top node
 */
public Node writeDescriptor(Node parent,T webBundleDesc){
  Node jarNode=super.writeDescriptor(parent,webBundleDesc);
  if (webBundleDesc.isDistributable()) {
    appendChild(jarNode,WebTagNames.DISTRIBUTABLE);
  }
  addInitParam(jarNode,WebTagNames.CONTEXT_PARAM,webBundleDesc.getContextParametersSet());
  FilterNode filterNode=new FilterNode();
  for (Enumeration filters=webBundleDesc.getServletFilters().elements(); filters.hasMoreElements(); ) {
    filterNode.writeDescriptor(jarNode,WebTagNames.FILTER,(ServletFilterDescriptor)filters.nextElement());
  }
  FilterMappingNode filterMappingNode=new FilterMappingNode();
  for (Enumeration mappings=webBundleDesc.getServletFilterMappings().elements(); mappings.hasMoreElements(); ) {
    filterMappingNode.writeDescriptor(jarNode,WebTagNames.FILTER_MAPPING,(ServletFilterMappingDescriptor)mappings.nextElement());
  }
  Vector appListeners=webBundleDesc.getAppListenerDescriptors();
  if (appListeners != null && !appListeners.isEmpty()) {
    ListenerNode listenerNode=new ListenerNode();
    for (Enumeration e=appListeners.elements(); e.hasMoreElements(); ) {
      listenerNode.writeDescriptor(jarNode,WebTagNames.LISTENER,(AppListenerDescriptorImpl)e.nextElement());
    }
  }
  Set servlets=webBundleDesc.getWebComponentDescriptors();
  if (servlets != null && !servlets.isEmpty()) {
    ServletNode servletNode=new ServletNode();
    for (Iterator e=servlets.iterator(); e.hasNext(); ) {
      WebComponentDescriptor aServlet=(WebComponentDescriptor)e.next();
      servletNode.writeDescriptor(jarNode,aServlet);
    }
    for (Iterator servletsIterator=servlets.iterator(); servletsIterator.hasNext(); ) {
      WebComponentDescriptor aServlet=(WebComponentDescriptor)servletsIterator.next();
      for (Iterator patterns=aServlet.getUrlPatternsSet().iterator(); patterns.hasNext(); ) {
        String pattern=(String)patterns.next();
        Node mappingNode=appendChild(jarNode,WebTagNames.SERVLET_MAPPING);
        appendTextChild(mappingNode,WebTagNames.SERVLET_NAME,aServlet.getCanonicalName());
        if (webBundleDesc.getSpecVersion().equals("String_Node_Str")) {
          if (!pattern.startsWith("String_Node_Str") && !pattern.startsWith("String_Node_Str")) {
            pattern="String_Node_Str" + pattern;
          }
        }
        appendTextChild(mappingNode,WebTagNames.URL_PATTERN,pattern);
      }
    }
  }
  MimeMappingNode mimeNode=new MimeMappingNode();
  for (Enumeration e=webBundleDesc.getMimeMappings(); e.hasMoreElements(); ) {
    MimeMappingDescriptor mimeMapping=(MimeMappingDescriptor)e.nextElement();
    mimeNode.writeDescriptor(jarNode,WebTagNames.MIME_MAPPING,mimeMapping);
  }
  Enumeration welcomeFiles=webBundleDesc.getWelcomeFiles();
  if (welcomeFiles.hasMoreElements()) {
    Node welcomeList=appendChild(jarNode,WebTagNames.WELCOME_FILE_LIST);
    while (welcomeFiles.hasMoreElements()) {
      appendTextChild(welcomeList,WebTagNames.WELCOME_FILE,(String)welcomeFiles.nextElement());
    }
  }
  Enumeration errorPages=webBundleDesc.getErrorPageDescriptors();
  if (errorPages.hasMoreElements()) {
    ErrorPageNode errorPageNode=new ErrorPageNode();
    while (errorPages.hasMoreElements()) {
      errorPageNode.writeDescriptor(jarNode,WebTagNames.ERROR_PAGE,(ErrorPageDescriptor)errorPages.nextElement());
    }
  }
  JspConfigDescriptorImpl jspConf=webBundleDesc.getJspConfigDescriptor();
  if (jspConf != null) {
    JspConfigNode ln=new JspConfigNode();
    ln.writeDescriptor(jarNode,WebTagNames.JSPCONFIG,jspConf);
  }
  Enumeration securityConstraints=webBundleDesc.getSecurityConstraints();
  if (securityConstraints.hasMoreElements()) {
    SecurityConstraintNode scNode=new SecurityConstraintNode();
    while (securityConstraints.hasMoreElements()) {
      SecurityConstraintImpl sc=(SecurityConstraintImpl)securityConstraints.nextElement();
      scNode.writeDescriptor(jarNode,WebTagNames.SECURITY_CONSTRAINT,sc);
    }
  }
  LoginConfigurationImpl lci=(LoginConfigurationImpl)webBundleDesc.getLoginConfiguration();
  if (lci != null) {
    LoginConfigNode lcn=new LoginConfigNode();
    lcn.writeDescriptor(jarNode,WebTagNames.LOGIN_CONFIG,lci);
  }
  Enumeration roles=webBundleDesc.getSecurityRoles();
  if (roles.hasMoreElements()) {
    SecurityRoleNode srNode=new SecurityRoleNode();
    while (roles.hasMoreElements()) {
      SecurityRoleDescriptor role=(SecurityRoleDescriptor)roles.nextElement();
      srNode.writeDescriptor(jarNode,WebTagNames.ROLE,role);
    }
  }
  writeEnvEntryDescriptors(jarNode,webBundleDesc.getEnvironmentProperties().iterator());
  writeEjbReferenceDescriptors(jarNode,webBundleDesc.getEjbReferenceDescriptors().iterator());
  writeServiceReferenceDescriptors(jarNode,webBundleDesc.getServiceReferenceDescriptors().iterator());
  writeResourceRefDescriptors(jarNode,webBundleDesc.getResourceReferenceDescriptors().iterator());
  writeResourceEnvRefDescriptors(jarNode,webBundleDesc.getResourceEnvReferenceDescriptors().iterator());
  writeMessageDestinationRefDescriptors(jarNode,webBundleDesc.getMessageDestinationReferenceDescriptors().iterator());
  writeEntityManagerReferenceDescriptors(jarNode,webBundleDesc.getEntityManagerReferenceDescriptors().iterator());
  writeEntityManagerFactoryReferenceDescriptors(jarNode,webBundleDesc.getEntityManagerFactoryReferenceDescriptors().iterator());
  writeLifeCycleCallbackDescriptors(jarNode,TagNames.POST_CONSTRUCT,webBundleDesc.getPostConstructDescriptors());
  writeLifeCycleCallbackDescriptors(jarNode,TagNames.PRE_DESTROY,webBundleDesc.getPreDestroyDescriptors());
  writeResourceDescriptors(jarNode,webBundleDesc.getAllResourcesDescriptors().iterator());
  writeMessageDestinations(jarNode,webBundleDesc.getMessageDestinations().iterator());
  LocaleEncodingMappingListDescriptor lemListDesc=webBundleDesc.getLocaleEncodingMappingListDescriptor();
  if (lemListDesc != null) {
    Node lemList=appendChild(jarNode,WebTagNames.LOCALE_ENCODING_MAPPING_LIST);
    LocaleEncodingMappingNode lemNode=new LocaleEncodingMappingNode();
    for (    LocaleEncodingMappingDescriptor lemDesc : lemListDesc.getLocaleEncodingMappingSet()) {
      lemNode.writeDescriptor(lemList,WebTagNames.LOCALE_ENCODING_MAPPING,lemDesc);
    }
  }
  if (webBundleDesc.getSessionConfig() != null) {
    SessionConfigNode scNode=new SessionConfigNode();
    scNode.writeDescriptor(jarNode,WebTagNames.SESSION_CONFIG,(SessionConfigDescriptor)webBundleDesc.getSessionConfig());
  }
  return jarNode;
}