Program: 116630
Project: 116630
Buggy source:
private LoadBalancerConfiguration transform(Node loadBalancerNode){
  LoadBalancerConfiguration configuration=new LoadBalancerConfiguration();
  if (loadBalancerNode == null || (!loadBalancerNode.getName().equals(Constants.CONF_ELEMENT_LOADBALANCER))) {
    throw new InvalidConfigurationException("String_Node_Str");
  }
  String defaultAlgorithm=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_ALGORITHM);
  validateRequiredPropertyInNode(Constants.CONF_PROPERTY_ALGORITHM,defaultAlgorithm,"String_Node_Str");
  configuration.setDefaultAlgorithmName(defaultAlgorithm);
  String failOver=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_FAILOVER);
  if (StringUtils.isNotBlank(failOver)) {
    configuration.setFailOverEnabled(Boolean.parseBoolean(failOver));
  }
  String sessionAffinity=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_SESSION_AFFINITY);
  if (StringUtils.isNotBlank(sessionAffinity)) {
    configuration.setSessionAffinityEnabled(Boolean.parseBoolean(sessionAffinity));
  }
  String sessionTimeout=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_SESSION_TIMEOUT);
  if (StringUtils.isNotBlank(sessionTimeout)) {
    configuration.setSessionTimeout(Long.parseLong(sessionTimeout));
  }
 else {
    configuration.setSessionTimeout(Constants.DEFAULT_SESSION_TIMEOUT);
  }
  String topologyEventListenerEnabled=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_EVENT_LISTENER);
  validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TOPOLOGY_EVENT_LISTENER,topologyEventListenerEnabled,Constants.CONF_ELEMENT_LOADBALANCER);
  configuration.setTopologyEventListenerEnabled(Boolean.parseBoolean(topologyEventListenerEnabled));
  if (configuration.isTopologyEventListenerEnabled()) {
    String topologyMemberIpType=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_MEMBER_IP_TYPE);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TOPOLOGY_MEMBER_IP_TYPE,topologyMemberIpType,Constants.CONF_ELEMENT_LOADBALANCER);
    configuration.setTopologyMemberIpType(transformMemberIpType(topologyMemberIpType));
  }
  String statsPublisherEnabled=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_STATS_PUBLISHER);
  if (StringUtils.isNotBlank(statsPublisherEnabled)) {
    configuration.setCepStatsPublisherEnabled(Boolean.parseBoolean(statsPublisherEnabled));
  }
  String multiTenancyEnabled=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_MULTI_TENANCY);
  if (StringUtils.isNotBlank(multiTenancyEnabled)) {
    configuration.setMultiTenancyEnabled(Boolean.parseBoolean(multiTenancyEnabled));
  }
  if (configuration.isTopologyEventListenerEnabled() || configuration.isMultiTenancyEnabled()) {
    String mbIp=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_MB_IP);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_MB_IP,mbIp,"String_Node_Str");
    configuration.setMbIp(mbIp);
    String mbPort=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_MB_PORT);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_MB_PORT,mbPort,"String_Node_Str");
    configuration.setMbPort(Integer.parseInt(mbPort));
  }
  if (configuration.isTopologyEventListenerEnabled()) {
    String serviceFilter=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_SERVICE_FILTER);
    if (StringUtils.isNotBlank(serviceFilter)) {
      configuration.setTopologyServiceFilter(serviceFilter);
    }
    String clusterFilter=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_CLUSTER_FILTER);
    if (StringUtils.isNotBlank(clusterFilter)) {
      configuration.setTopologyClusterFilter(clusterFilter);
    }
    String memberFilter=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_MEMBER_FILTER);
    if (StringUtils.isNotBlank(memberFilter)) {
      configuration.setTopologyMemberFilter(memberFilter);
    }
  }
  if (configuration.isCepStatsPublisherEnabled()) {
    String cepIp=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_IP);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_CEP_IP,cepIp,"String_Node_Str");
    configuration.setCepIp(cepIp);
    String cepPort=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_PORT);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_CEP_PORT,cepPort,"String_Node_Str");
    configuration.setCepPort(Integer.parseInt(cepPort));
    String networkPartitionId=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_NETWORK_PARTITION_ID);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_NETWORK_PARTITION_ID,networkPartitionId,"String_Node_Str");
    configuration.setNetworkPartitionId(networkPartitionId);
  }
  if (configuration.isMultiTenancyEnabled()) {
    String tenantIdentifierStr=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TENANT_IDENTIFIER);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TENANT_IDENTIFIER,tenantIdentifierStr,"String_Node_Str");
    if (tenantIdentifierStr.equals(Constants.CONF_PROPERTY_VALUE_TENANT_ID)) {
      configuration.setTenantIdentifier(TenantIdentifier.TenantId);
    }
 else     if (tenantIdentifierStr.equals(Constants.CONF_PROPERTY_VALUE_TENANT_DOMAIN)) {
      configuration.setTenantIdentifier(TenantIdentifier.TenantDomain);
    }
 else {
      throw new InvalidConfigurationException(String.format("String_Node_Str",tenantIdentifierStr));
    }
    String tenantIdentifierRegex=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TENANT_IDENTIFIER_REGEX);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TENANT_IDENTIFIER_REGEX,tenantIdentifierRegex,"String_Node_Str");
    try {
      Pattern.compile(tenantIdentifierRegex);
    }
 catch (    Exception e) {
      throw new InvalidConfigurationException(String.format("String_Node_Str",tenantIdentifierRegex),e);
    }
    configuration.setTenantIdentifierRegex(tenantIdentifierRegex);
  }
  Node algorithmsNode=loadBalancerNode.findChildNodeByName(Constants.CONF_ELEMENT_ALGORITHMS);
  validateRequiredNode(loadBalancerNode,Constants.CONF_ELEMENT_ALGORITHMS);
  for (  Node algorithmNode : algorithmsNode.getChildNodes()) {
    String className=algorithmNode.getProperty(Constants.CONF_PROPERTY_CLASS_NAME);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_CLASS_NAME,className,"String_Node_Str",algorithmNode.getName());
    Algorithm algorithm=new Algorithm(algorithmNode.getName(),className);
    configuration.addAlgorithm(algorithm);
  }
  if (!configuration.isTopologyEventListenerEnabled()) {
    Node servicesNode=loadBalancerNode.findChildNodeByName(Constants.CONF_ELEMENT_SERVICES);
    validateRequiredNode(servicesNode,Constants.CONF_ELEMENT_SERVICES);
    for (    Node serviceNode : servicesNode.getChildNodes()) {
      ServiceType serviceType=ServiceType.SingleTenant;
      String multiTenant=serviceNode.getProperty(Constants.CONF_PROPERTY_MULTI_TENANT);
      if (StringUtils.isNotBlank(multiTenant) && (Boolean.parseBoolean(multiTenant))) {
        serviceType=ServiceType.MultiTenant;
      }
      Service service=new Service(serviceNode.getName(),serviceType);
      Node clustersNode=serviceNode.findChildNodeByName(Constants.CONF_ELEMENT_CLUSTERS);
      for (      Node clusterNode : clustersNode.getChildNodes()) {
        String clusterId=clusterNode.getName();
        Cluster cluster=new Cluster(service.getServiceName(),clusterId,null,null);
        String tenantRange=clusterNode.getProperty(Constants.CONF_PROPERTY_TENANT_RANGE);
        if (StringUtils.isNotBlank(tenantRange)) {
          if (service.getServiceType() != ServiceType.MultiTenant) {
            throw new InvalidConfigurationException(String.format("String_Node_Str",Constants.CONF_PROPERTY_TENANT_RANGE,service.getServiceName(),cluster.getClusterId()));
          }
          cluster.setTenantRange(tenantRange);
        }
        String algorithm=clusterNode.getProperty(Constants.CONF_PROPERTY_ALGORITHM);
        if (StringUtils.isNotBlank(algorithm)) {
          cluster.setLoadBalanceAlgorithmName(algorithm);
        }
        String hosts=clusterNode.getProperty(Constants.CONF_ELEMENT_HOSTS);
        validateRequiredPropertyInNode(Constants.CONF_ELEMENT_HOSTS,hosts,"String_Node_Str",clusterNode.getName());
        String[] hostsArray=hosts.split("String_Node_Str");
        for (        String hostsName : hostsArray) {
          cluster.addHostName(hostsName.trim());
        }
        Node membersNode=clusterNode.findChildNodeByName(Constants.CONF_ELEMENT_MEMBERS);
        validateRequiredNode(membersNode,Constants.CONF_ELEMENT_MEMBERS,String.format("String_Node_Str",clusterId));
        for (        Node memberNode : membersNode.getChildNodes()) {
          String memberId=memberNode.getName();
          Member member=new Member(cluster.getServiceName(),cluster.getClusterId(),Constants.STATIC_NETWORK_PARTITION,Constants.STATIC_PARTITION,memberId);
          String ip=memberNode.getProperty(Constants.CONF_PROPERTY_IP);
          validateRequiredPropertyInNode(Constants.CONF_PROPERTY_IP,ip,String.format("String_Node_Str",memberId));
          member.setMemberIp(ip);
          Node portsNode=memberNode.findChildNodeByName(Constants.CONF_ELEMENT_PORTS);
          validateRequiredNode(portsNode,Constants.CONF_ELEMENT_PORTS,String.format("String_Node_Str",memberId));
          for (          Node portNode : portsNode.getChildNodes()) {
            String value=portNode.getProperty(Constants.CONF_PROPERTY_VALUE);
            validateRequiredPropertyInNode(Constants.CONF_PROPERTY_VALUE,value,"String_Node_Str",String.format("String_Node_Str",memberId));
            String proxy=portNode.getProperty(Constants.CONF_PROPERTY_PROXY);
            validateRequiredPropertyInNode(Constants.CONF_PROPERTY_PROXY,proxy,"String_Node_Str",String.format("String_Node_Str",memberId));
            Port port=new Port(portNode.getName(),Integer.valueOf(value),Integer.valueOf(proxy));
            member.addPort(port);
          }
          cluster.addMember(member);
        }
        service.addCluster(cluster);
        try {
          TopologyManager.acquireWriteLock();
          if (!TopologyManager.getTopology().serviceExists(service.getServiceName())) {
            TopologyManager.getTopology().addService(service);
          }
        }
  finally {
          TopologyManager.releaseWriteLock();
        }
        LoadBalancerContextUtil.addClusterToLbContext(cluster);
      }
    }
  }
  return configuration;
}

Fixed version (ground truth):
private LoadBalancerConfiguration transform(Node loadBalancerNode){
  LoadBalancerConfiguration configuration=new LoadBalancerConfiguration();
  if (loadBalancerNode == null || (!loadBalancerNode.getName().equals(Constants.CONF_ELEMENT_LOADBALANCER))) {
    throw new InvalidConfigurationException("String_Node_Str");
  }
  String defaultAlgorithm=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_ALGORITHM);
  validateRequiredPropertyInNode(Constants.CONF_PROPERTY_ALGORITHM,defaultAlgorithm,"String_Node_Str");
  configuration.setDefaultAlgorithmName(defaultAlgorithm);
  String failOver=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_FAILOVER);
  if (StringUtils.isNotBlank(failOver)) {
    configuration.setFailOverEnabled(Boolean.parseBoolean(failOver));
  }
  String sessionAffinity=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_SESSION_AFFINITY);
  if (StringUtils.isNotBlank(sessionAffinity)) {
    configuration.setSessionAffinityEnabled(Boolean.parseBoolean(sessionAffinity));
  }
  String sessionTimeout=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_SESSION_TIMEOUT);
  if (StringUtils.isNotBlank(sessionTimeout)) {
    configuration.setSessionTimeout(Long.parseLong(sessionTimeout));
  }
 else {
    configuration.setSessionTimeout(Constants.DEFAULT_SESSION_TIMEOUT);
  }
  String topologyEventListenerEnabled=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_EVENT_LISTENER);
  validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TOPOLOGY_EVENT_LISTENER,topologyEventListenerEnabled,Constants.CONF_ELEMENT_LOADBALANCER);
  configuration.setTopologyEventListenerEnabled(Boolean.parseBoolean(topologyEventListenerEnabled));
  if (configuration.isTopologyEventListenerEnabled()) {
    String topologyMemberIpType=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_MEMBER_IP_TYPE);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TOPOLOGY_MEMBER_IP_TYPE,topologyMemberIpType,Constants.CONF_ELEMENT_LOADBALANCER);
    configuration.setTopologyMemberIpType(transformMemberIpType(topologyMemberIpType));
  }
  String statsPublisherEnabled=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_STATS_PUBLISHER);
  if (StringUtils.isNotBlank(statsPublisherEnabled)) {
    configuration.setCepStatsPublisherEnabled(Boolean.parseBoolean(statsPublisherEnabled));
  }
  String multiTenancyEnabled=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_MULTI_TENANCY);
  if (StringUtils.isNotBlank(multiTenancyEnabled)) {
    configuration.setMultiTenancyEnabled(Boolean.parseBoolean(multiTenancyEnabled));
  }
  if (configuration.isTopologyEventListenerEnabled() || configuration.isMultiTenancyEnabled()) {
    String mbIp=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_MB_IP);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_MB_IP,mbIp,"String_Node_Str");
    configuration.setMbIp(mbIp);
    String mbPort=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_MB_PORT);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_MB_PORT,mbPort,"String_Node_Str");
    configuration.setMbPort(Integer.parseInt(mbPort));
  }
  if (configuration.isTopologyEventListenerEnabled()) {
    String serviceFilter=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_SERVICE_FILTER);
    if (StringUtils.isNotBlank(serviceFilter)) {
      configuration.setTopologyServiceFilter(serviceFilter);
    }
    String clusterFilter=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_CLUSTER_FILTER);
    if (StringUtils.isNotBlank(clusterFilter)) {
      configuration.setTopologyClusterFilter(clusterFilter);
    }
    String memberFilter=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_MEMBER_FILTER);
    if (StringUtils.isNotBlank(memberFilter)) {
      configuration.setTopologyMemberFilter(memberFilter);
    }
  }
  if (configuration.isCepStatsPublisherEnabled()) {
    String cepIp=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_IP);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_CEP_IP,cepIp,"String_Node_Str");
    configuration.setCepIp(cepIp);
    String cepPort=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_PORT);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_CEP_PORT,cepPort,"String_Node_Str");
    configuration.setCepPort(Integer.parseInt(cepPort));
    String networkPartitionId=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_NETWORK_PARTITION_ID);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_NETWORK_PARTITION_ID,networkPartitionId,"String_Node_Str");
    configuration.setNetworkPartitionId(networkPartitionId);
  }
  if (configuration.isMultiTenancyEnabled()) {
    String tenantIdentifierStr=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TENANT_IDENTIFIER);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TENANT_IDENTIFIER,tenantIdentifierStr,"String_Node_Str");
    if (tenantIdentifierStr.equals(Constants.CONF_PROPERTY_VALUE_TENANT_ID)) {
      configuration.setTenantIdentifier(TenantIdentifier.TenantId);
    }
 else     if (tenantIdentifierStr.equals(Constants.CONF_PROPERTY_VALUE_TENANT_DOMAIN)) {
      configuration.setTenantIdentifier(TenantIdentifier.TenantDomain);
    }
 else {
      throw new InvalidConfigurationException(String.format("String_Node_Str",tenantIdentifierStr));
    }
    String tenantIdentifierRegex=loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TENANT_IDENTIFIER_REGEX);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TENANT_IDENTIFIER_REGEX,tenantIdentifierRegex,"String_Node_Str");
    try {
      Pattern.compile(tenantIdentifierRegex);
    }
 catch (    Exception e) {
      throw new InvalidConfigurationException(String.format("String_Node_Str",tenantIdentifierRegex),e);
    }
    configuration.setTenantIdentifierRegex(tenantIdentifierRegex);
  }
  Node algorithmsNode=loadBalancerNode.findChildNodeByName(Constants.CONF_ELEMENT_ALGORITHMS);
  validateRequiredNode(loadBalancerNode,Constants.CONF_ELEMENT_ALGORITHMS);
  for (  Node algorithmNode : algorithmsNode.getChildNodes()) {
    String className=algorithmNode.getProperty(Constants.CONF_PROPERTY_CLASS_NAME);
    validateRequiredPropertyInNode(Constants.CONF_PROPERTY_CLASS_NAME,className,"String_Node_Str",algorithmNode.getName());
    Algorithm algorithm=new Algorithm(algorithmNode.getName(),className);
    configuration.addAlgorithm(algorithm);
  }
  if (!configuration.isTopologyEventListenerEnabled()) {
    Node servicesNode=loadBalancerNode.findChildNodeByName(Constants.CONF_ELEMENT_SERVICES);
    validateRequiredNode(servicesNode,Constants.CONF_ELEMENT_SERVICES);
    for (    Node serviceNode : servicesNode.getChildNodes()) {
      ServiceType serviceType=ServiceType.SingleTenant;
      String multiTenant=serviceNode.getProperty(Constants.CONF_PROPERTY_MULTI_TENANT);
      if (StringUtils.isNotBlank(multiTenant) && (Boolean.parseBoolean(multiTenant))) {
        serviceType=ServiceType.MultiTenant;
      }
      Service service=new Service(serviceNode.getName(),serviceType);
      Node clustersNode=serviceNode.findChildNodeByName(Constants.CONF_ELEMENT_CLUSTERS);
      for (      Node clusterNode : clustersNode.getChildNodes()) {
        String clusterId=clusterNode.getName();
        Cluster cluster=new Cluster(service.getServiceName(),clusterId,null,null);
        String tenantRange=clusterNode.getProperty(Constants.CONF_PROPERTY_TENANT_RANGE);
        if (StringUtils.isNotBlank(tenantRange)) {
          if (service.getServiceType() != ServiceType.MultiTenant) {
            throw new InvalidConfigurationException(String.format("String_Node_Str",Constants.CONF_PROPERTY_TENANT_RANGE,service.getServiceName(),cluster.getClusterId()));
          }
          cluster.setTenantRange(tenantRange);
        }
        String algorithm=clusterNode.getProperty(Constants.CONF_PROPERTY_ALGORITHM);
        if (StringUtils.isNotBlank(algorithm)) {
          cluster.setLoadBalanceAlgorithmName(algorithm);
        }
        String hosts=clusterNode.getProperty(Constants.CONF_ELEMENT_HOSTS);
        validateRequiredPropertyInNode(Constants.CONF_ELEMENT_HOSTS,hosts,"String_Node_Str",clusterNode.getName());
        String[] hostsArray=hosts.split("String_Node_Str");
        for (        String hostsName : hostsArray) {
          cluster.addHostName(hostsName.trim());
        }
        Node membersNode=clusterNode.findChildNodeByName(Constants.CONF_ELEMENT_MEMBERS);
        validateRequiredNode(membersNode,Constants.CONF_ELEMENT_MEMBERS,String.format("String_Node_Str",clusterId));
        for (        Node memberNode : membersNode.getChildNodes()) {
          String memberId=memberNode.getName();
          Member member=new Member(cluster.getServiceName(),cluster.getClusterId(),Constants.STATIC_NETWORK_PARTITION,Constants.STATIC_PARTITION,memberId);
          String ip=memberNode.getProperty(Constants.CONF_PROPERTY_IP);
          validateRequiredPropertyInNode(Constants.CONF_PROPERTY_IP,ip,String.format("String_Node_Str",memberId));
          member.setMemberIp(ip);
          Node portsNode=memberNode.findChildNodeByName(Constants.CONF_ELEMENT_PORTS);
          validateRequiredNode(portsNode,Constants.CONF_ELEMENT_PORTS,String.format("String_Node_Str",memberId));
          for (          Node portNode : portsNode.getChildNodes()) {
            String value=portNode.getProperty(Constants.CONF_PROPERTY_VALUE);
            validateRequiredPropertyInNode(Constants.CONF_PROPERTY_VALUE,value,"String_Node_Str",String.format("String_Node_Str",memberId));
            String proxy=portNode.getProperty(Constants.CONF_PROPERTY_PROXY);
            validateRequiredPropertyInNode(Constants.CONF_PROPERTY_PROXY,proxy,"String_Node_Str",String.format("String_Node_Str",memberId));
            Port port=new Port(portNode.getName(),Integer.valueOf(value),Integer.valueOf(proxy));
            member.addPort(port);
          }
          member.setStatus(MemberStatus.Activated);
          cluster.addMember(member);
        }
        service.addCluster(cluster);
        try {
          TopologyManager.acquireWriteLock();
          if (!TopologyManager.getTopology().serviceExists(service.getServiceName())) {
            TopologyManager.getTopology().addService(service);
          }
        }
  finally {
          TopologyManager.releaseWriteLock();
        }
        LoadBalancerContextUtil.addClusterToLbContext(cluster);
      }
    }
  }
  return configuration;
}