Program: 28363
Project: 28363
Buggy source:
/** 
 * write the descriptor class to a DOM tree and return it
 * @param parent node for the DOM tree
 * @param bundleDescriptor the descriptor to write
 * @return the DOM tree top node
 */
@Override public Node writeDescriptor(Node parent,WebBundleDescriptorImpl bundleDescriptor){
  Element web=(Element)super.writeDescriptor(parent,bundleDescriptor);
  SunWebAppImpl sunWebApp=(SunWebAppImpl)bundleDescriptor.getSunDescriptor();
  appendTextChild(web,RuntimeTagNames.CONTEXT_ROOT,bundleDescriptor.getContextRoot());
  SecurityRoleMapping[] roleMappings=sunWebApp.getSecurityRoleMapping();
  if (roleMappings != null && roleMappings.length > 0) {
    SecurityRoleMappingNode srmn=new SecurityRoleMappingNode();
    for (int i=0; i < roleMappings.length; i++) {
      srmn.writeDescriptor(web,RuntimeTagNames.SECURITY_ROLE_MAPPING,roleMappings[i]);
    }
  }
  Set servlets=bundleDescriptor.getServletDescriptors();
  if (servlets != null) {
    org.glassfish.web.deployment.node.runtime.gf.ServletNode node=new org.glassfish.web.deployment.node.runtime.gf.ServletNode();
    for (Iterator itr=servlets.iterator(); itr.hasNext(); ) {
      WebComponentDescriptor servlet=(WebComponentDescriptor)itr.next();
      node.writeDescriptor(web,RuntimeTagNames.SERVLET,servlet);
    }
  }
  IdempotentUrlPattern[] patterns=sunWebApp.getIdempotentUrlPatterns();
  if (patterns != null && patterns.length > 0) {
    IdempotentUrlPatternNode node=new IdempotentUrlPatternNode();
    for (int i=0; i < patterns.length; i++) {
      node.writeDescriptor(web,RuntimeTagNames.IDEMPOTENT_URL_PATTERN,patterns[i]);
    }
  }
  if (sunWebApp.getSessionConfig() != null) {
    SessionConfigNode scn=new SessionConfigNode();
    scn.writeDescriptor(web,RuntimeTagNames.SESSION_CONFIG,sunWebApp.getSessionConfig());
  }
  Set<EjbReference> ejbRefs=bundleDescriptor.getEjbReferenceDescriptors();
  if (ejbRefs != null && ejbRefs.size() > 0) {
    EjbRefNode node=new EjbRefNode();
    for (    EjbReference ejbRef : ejbRefs) {
      node.writeDescriptor(web,RuntimeTagNames.EJB_REF,ejbRef);
    }
  }
  Set<ResourceReferenceDescriptor> resourceRefs=bundleDescriptor.getResourceReferenceDescriptors();
  if (resourceRefs != null && resourceRefs.size() > 0) {
    ResourceRefNode node=new ResourceRefNode();
    for (    ResourceReferenceDescriptor resourceRef : resourceRefs) {
      node.writeDescriptor(web,RuntimeTagNames.RESOURCE_REF,resourceRef);
    }
  }
  Set<ResourceEnvReferenceDescriptor> resourceEnvRefs=bundleDescriptor.getResourceEnvReferenceDescriptors();
  if (resourceEnvRefs != null && resourceEnvRefs.size() > 0) {
    ResourceEnvRefNode node=new ResourceEnvRefNode();
    for (    ResourceEnvReferenceDescriptor resourceEnvRef : resourceEnvRefs) {
      node.writeDescriptor(web,RuntimeTagNames.RESOURCE_ENV_REF,resourceEnvRef);
    }
  }
  if (bundleDescriptor.hasServiceReferenceDescriptors()) {
    ServiceRefNode serviceNode=new ServiceRefNode();
    for (Iterator serviceItr=bundleDescriptor.getServiceReferenceDescriptors().iterator(); serviceItr.hasNext(); ) {
      ServiceReferenceDescriptor next=(ServiceReferenceDescriptor)serviceItr.next();
      serviceNode.writeDescriptor(web,WebServicesTagNames.SERVICE_REF,next);
    }
  }
  MessageDestinationRefNode.writeMessageDestinationReferences(web,bundleDescriptor);
  Cache cache=sunWebApp.getCache();
  if (cache != null) {
    CacheNode cn=new CacheNode();
    cn.writeDescriptor(web,RuntimeTagNames.CACHE,cache);
  }
  ClassLoader classLoader=sunWebApp.getClassLoader();
  if (classLoader != null) {
    ClassLoaderNode cln=new ClassLoaderNode();
    cln.writeDescriptor(web,RuntimeTagNames.CLASS_LOADER,classLoader);
  }
  if (sunWebApp.getJspConfig() != null) {
    WebPropertyNode propertyNode=new WebPropertyNode();
    Node jspConfig=appendChild(web,RuntimeTagNames.JSP_CONFIG);
    propertyNode.writeDescriptor(jspConfig,RuntimeTagNames.PROPERTY,sunWebApp.getJspConfig().getWebProperty());
  }
  if (sunWebApp.getLocaleCharsetInfo() != null) {
    LocaleCharsetInfoNode localeNode=new LocaleCharsetInfoNode();
    localeNode.writeDescriptor(web,RuntimeTagNames.LOCALE_CHARSET_INFO,sunWebApp.getLocaleCharsetInfo());
  }
  if (sunWebApp.isParameterEncoding()) {
    Element parameter=appendChild(web,RuntimeTagNames.PARAMETER_ENCODING);
    if (sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING,SunWebApp.FORM_HINT_FIELD) != null) {
      setAttribute(parameter,RuntimeTagNames.FORM_HINT_FIELD,sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING,SunWebApp.FORM_HINT_FIELD));
    }
    if (sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING,SunWebApp.DEFAULT_CHARSET) != null) {
      setAttribute(parameter,RuntimeTagNames.DEFAULT_CHARSET,sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING,SunWebApp.DEFAULT_CHARSET));
    }
  }
  if (sunWebApp.getWebProperty() != null) {
    WebPropertyNode props=new WebPropertyNode();
    props.writeDescriptor(web,RuntimeTagNames.PROPERTY,sunWebApp.getWebProperty());
  }
  if (sunWebApp.getValve() != null) {
    ValveNode valve=new ValveNode();
    valve.writeDescriptor(web,RuntimeTagNames.VALVE,sunWebApp.getValve());
  }
  RuntimeDescriptorNode.writeMessageDestinationInfo(web,bundleDescriptor);
  WebServiceRuntimeNode webServiceNode=new WebServiceRuntimeNode();
  webServiceNode.writeWebServiceRuntimeInfo(web,bundleDescriptor);
  if (sunWebApp.getAttributeValue(SunWebApp.ERROR_URL) != null) {
    setAttribute(web,RuntimeTagNames.ERROR_URL,sunWebApp.getAttributeValue(SunWebApp.ERROR_URL));
  }
  if (sunWebApp.getAttributeValue(SunWebApp.HTTPSERVLET_SECURITY_PROVIDER) != null) {
    setAttribute(web,RuntimeTagNames.HTTPSERVLET_SECURITY_PROVIDER,sunWebApp.getAttributeValue(SunWebApp.HTTPSERVLET_SECURITY_PROVIDER));
  }
  appendTextChild(web,RuntimeTagNames.KEEP_STATE,String.valueOf(bundleDescriptor.getKeepState()));
  return web;
}

Fixed version (ground truth):
/** 
 * write the descriptor class to a DOM tree and return it
 * @param parent node for the DOM tree
 * @param bundleDescriptor the descriptor to write
 * @return the DOM tree top node
 */
@Override public Node writeDescriptor(Node parent,WebBundleDescriptorImpl bundleDescriptor){
  Element web=(Element)super.writeDescriptor(parent,bundleDescriptor);
  SunWebAppImpl sunWebApp=(SunWebAppImpl)bundleDescriptor.getSunDescriptor();
  appendTextChild(web,RuntimeTagNames.CONTEXT_ROOT,bundleDescriptor.getContextRoot());
  SecurityRoleMapping[] roleMappings=sunWebApp.getSecurityRoleMapping();
  if (roleMappings != null && roleMappings.length > 0) {
    SecurityRoleMappingNode srmn=new SecurityRoleMappingNode();
    for (int i=0; i < roleMappings.length; i++) {
      srmn.writeDescriptor(web,RuntimeTagNames.SECURITY_ROLE_MAPPING,roleMappings[i]);
    }
  }
  Set servlets=bundleDescriptor.getServletDescriptors();
  org.glassfish.web.deployment.node.runtime.gf.ServletNode servletNode=new org.glassfish.web.deployment.node.runtime.gf.ServletNode();
  for (Iterator itr=servlets.iterator(); itr.hasNext(); ) {
    WebComponentDescriptor servlet=(WebComponentDescriptor)itr.next();
    servletNode.writeDescriptor(web,RuntimeTagNames.SERVLET,servlet);
  }
  IdempotentUrlPattern[] patterns=sunWebApp.getIdempotentUrlPatterns();
  if (patterns != null && patterns.length > 0) {
    IdempotentUrlPatternNode node=new IdempotentUrlPatternNode();
    for (int i=0; i < patterns.length; i++) {
      node.writeDescriptor(web,RuntimeTagNames.IDEMPOTENT_URL_PATTERN,patterns[i]);
    }
  }
  if (sunWebApp.getSessionConfig() != null) {
    SessionConfigNode scn=new SessionConfigNode();
    scn.writeDescriptor(web,RuntimeTagNames.SESSION_CONFIG,sunWebApp.getSessionConfig());
  }
  Set<EjbReference> ejbRefs=bundleDescriptor.getEjbReferenceDescriptors();
  if (ejbRefs.size() > 0) {
    EjbRefNode node=new EjbRefNode();
    for (    EjbReference ejbRef : ejbRefs) {
      node.writeDescriptor(web,RuntimeTagNames.EJB_REF,ejbRef);
    }
  }
  Set<ResourceReferenceDescriptor> resourceRefs=bundleDescriptor.getResourceReferenceDescriptors();
  if (resourceRefs.size() > 0) {
    ResourceRefNode node=new ResourceRefNode();
    for (    ResourceReferenceDescriptor resourceRef : resourceRefs) {
      node.writeDescriptor(web,RuntimeTagNames.RESOURCE_REF,resourceRef);
    }
  }
  Set<ResourceEnvReferenceDescriptor> resourceEnvRefs=bundleDescriptor.getResourceEnvReferenceDescriptors();
  if (resourceEnvRefs.size() > 0) {
    ResourceEnvRefNode node=new ResourceEnvRefNode();
    for (    ResourceEnvReferenceDescriptor resourceEnvRef : resourceEnvRefs) {
      node.writeDescriptor(web,RuntimeTagNames.RESOURCE_ENV_REF,resourceEnvRef);
    }
  }
  if (bundleDescriptor.hasServiceReferenceDescriptors()) {
    ServiceRefNode serviceNode=new ServiceRefNode();
    for (Iterator serviceItr=bundleDescriptor.getServiceReferenceDescriptors().iterator(); serviceItr.hasNext(); ) {
      ServiceReferenceDescriptor next=(ServiceReferenceDescriptor)serviceItr.next();
      serviceNode.writeDescriptor(web,WebServicesTagNames.SERVICE_REF,next);
    }
  }
  MessageDestinationRefNode.writeMessageDestinationReferences(web,bundleDescriptor);
  Cache cache=sunWebApp.getCache();
  if (cache != null) {
    CacheNode cn=new CacheNode();
    cn.writeDescriptor(web,RuntimeTagNames.CACHE,cache);
  }
  ClassLoader classLoader=sunWebApp.getClassLoader();
  if (classLoader != null) {
    ClassLoaderNode cln=new ClassLoaderNode();
    cln.writeDescriptor(web,RuntimeTagNames.CLASS_LOADER,classLoader);
  }
  if (sunWebApp.getJspConfig() != null) {
    WebPropertyNode propertyNode=new WebPropertyNode();
    Node jspConfig=appendChild(web,RuntimeTagNames.JSP_CONFIG);
    propertyNode.writeDescriptor(jspConfig,RuntimeTagNames.PROPERTY,sunWebApp.getJspConfig().getWebProperty());
  }
  if (sunWebApp.getLocaleCharsetInfo() != null) {
    LocaleCharsetInfoNode localeNode=new LocaleCharsetInfoNode();
    localeNode.writeDescriptor(web,RuntimeTagNames.LOCALE_CHARSET_INFO,sunWebApp.getLocaleCharsetInfo());
  }
  if (sunWebApp.isParameterEncoding()) {
    Element parameter=appendChild(web,RuntimeTagNames.PARAMETER_ENCODING);
    if (sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING,SunWebApp.FORM_HINT_FIELD) != null) {
      setAttribute(parameter,RuntimeTagNames.FORM_HINT_FIELD,sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING,SunWebApp.FORM_HINT_FIELD));
    }
    if (sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING,SunWebApp.DEFAULT_CHARSET) != null) {
      setAttribute(parameter,RuntimeTagNames.DEFAULT_CHARSET,sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING,SunWebApp.DEFAULT_CHARSET));
    }
  }
  WebPropertyNode props=new WebPropertyNode();
  props.writeDescriptor(web,RuntimeTagNames.PROPERTY,sunWebApp.getWebProperty());
  if (sunWebApp.getValve() != null) {
    ValveNode valve=new ValveNode();
    valve.writeDescriptor(web,RuntimeTagNames.VALVE,sunWebApp.getValve());
  }
  RuntimeDescriptorNode.writeMessageDestinationInfo(web,bundleDescriptor);
  WebServiceRuntimeNode webServiceNode=new WebServiceRuntimeNode();
  webServiceNode.writeWebServiceRuntimeInfo(web,bundleDescriptor);
  if (sunWebApp.getAttributeValue(SunWebApp.ERROR_URL) != null) {
    setAttribute(web,RuntimeTagNames.ERROR_URL,sunWebApp.getAttributeValue(SunWebApp.ERROR_URL));
  }
  if (sunWebApp.getAttributeValue(SunWebApp.HTTPSERVLET_SECURITY_PROVIDER) != null) {
    setAttribute(web,RuntimeTagNames.HTTPSERVLET_SECURITY_PROVIDER,sunWebApp.getAttributeValue(SunWebApp.HTTPSERVLET_SECURITY_PROVIDER));
  }
  appendTextChild(web,RuntimeTagNames.KEEP_STATE,String.valueOf(bundleDescriptor.getKeepState()));
  return web;
}