Program: 49132
Project: 49132
Buggy source:
private void convertClusterConfig(ClusterEntity clusterEntity,ClusterCreate clusterConfig){
  logger.debug("String_Node_Str" + clusterEntity.getName());
  CommonClusterExpandPolicy.expandDistro(clusterEntity,clusterConfig,distroMgr);
  clusterConfig.setTopologyPolicy(clusterEntity.getTopologyPolicy());
  Map<String,String> hostToRackMap=rackInfoMgr.exportHostRackMap();
  if ((clusterConfig.getTopologyPolicy() == TopologyType.RACK_AS_RACK || clusterConfig.getTopologyPolicy() == TopologyType.HVE) && hostToRackMap.isEmpty()) {
    logger.error("String_Node_Str");
    throw ClusterConfigException.INVALID_TOPOLOGY_POLICY(clusterConfig.getTopologyPolicy(),"String_Node_Str");
  }
  clusterConfig.setHostToRackMap(hostToRackMap);
  clusterConfig.setTemplateId(templateId);
  if (clusterEntity.getVcRpNames() != null) {
    logger.debug("String_Node_Str");
    String[] rpNames=clusterEntity.getVcRpNameList().toArray(new String[]{});
    List<VcCluster> vcClusters=rpMgr.getVcResourcePoolByNameList(rpNames);
    clusterConfig.setVcClusters(vcClusters);
    clusterConfig.setRpNames(clusterEntity.getVcRpNameList());
  }
 else {
    logger.debug("String_Node_Str");
  }
  if (clusterEntity.getVcDatastoreNameList() != null) {
    logger.debug("String_Node_Str");
    Set<String> sharedPattern=datastoreMgr.getSharedDatastoresByNames(clusterEntity.getVcDatastoreNameList());
    clusterConfig.setSharedPattern(sharedPattern);
    Set<String> localPattern=datastoreMgr.getLocalDatastoresByNames(clusterEntity.getVcDatastoreNameList());
    clusterConfig.setLocalPattern(localPattern);
    clusterConfig.setDsNames(clusterEntity.getVcDatastoreNameList());
  }
 else {
    logger.debug("String_Node_Str");
  }
  List<NodeGroupCreate> nodeGroups=new ArrayList<NodeGroupCreate>();
  Set<NodeGroupEntity> nodeGroupEntities=clusterEntity.getNodeGroups();
  long instanceNum=0;
  for (  NodeGroupEntity ngEntity : nodeGroupEntities) {
    NodeGroupCreate group=convertNodeGroups(clusterEntity.getDistro(),ngEntity,clusterEntity.getName());
    nodeGroups.add(group);
    instanceNum+=group.getInstanceNum();
  }
  sortGroups(nodeGroups);
  clusterConfig.setNodeGroups(nodeGroups.toArray(new NodeGroupCreate[]{}));
  NetworkEntity networkEntity=clusterEntity.getNetwork();
  List<NetworkAdd> networking=new ArrayList<NetworkAdd>();
  NetworkAdd network=new NetworkAdd();
  network.setPortGroup(networkEntity.getPortGroup());
  network.setDhcp(networkEntity.getAllocType() == NetworkEntity.AllocType.DHCP);
  if (!network.isDhcp()) {
    logger.debug("String_Node_Str");
    List<IpBlockEntity> ipBlockEntities=networkMgr.getAllocatedIpBlocks(networkEntity,clusterEntity.getId());
    long allocatedIpNum=IpBlockEntity.count(ipBlockEntities);
    if (allocatedIpNum < instanceNum) {
      long newNum=instanceNum - allocatedIpNum;
      List<IpBlockEntity> newIpBlockEntities=networkMgr.alloc(networkEntity,clusterEntity.getId(),newNum);
      ipBlockEntities.addAll(newIpBlockEntities);
    }
    network.setDns1(networkEntity.getDns1());
    network.setDns2(networkEntity.getDns2());
    network.setGateway(networkEntity.getGateway());
    network.setNetmask(networkEntity.getNetmask());
    List<IpBlock> ips=new ArrayList<IpBlock>();
    for (    IpBlockEntity ipBlockEntity : ipBlockEntities) {
      IpBlock ip=new IpBlock();
      ip.setBeginIp(ipBlockEntity.getBeginAddress());
      ip.setEndIp(ipBlockEntity.getEndAddress());
      ips.add(ip);
    }
    network.setIp(ips);
  }
  networking.add(network);
  clusterConfig.setNetworking(networking);
  clusterConfig.setNetworkName(networkEntity.getName());
  if (clusterEntity.getHadoopConfig() != null) {
    Map hadoopConfig=(new Gson()).fromJson(clusterEntity.getHadoopConfig(),Map.class);
    clusterConfig.setConfiguration((Map<String,Object>)hadoopConfig);
  }
}

Fixed version (ground truth):
private void convertClusterConfig(ClusterEntity clusterEntity,ClusterCreate clusterConfig){
  logger.debug("String_Node_Str" + clusterEntity.getName());
  CommonClusterExpandPolicy.expandDistro(clusterEntity,clusterConfig,distroMgr);
  clusterConfig.setTopologyPolicy(clusterEntity.getTopologyPolicy());
  Map<String,String> hostToRackMap=rackInfoMgr.exportHostRackMap();
  if ((clusterConfig.getTopologyPolicy() == TopologyType.RACK_AS_RACK || clusterConfig.getTopologyPolicy() == TopologyType.HVE) && hostToRackMap.isEmpty()) {
    logger.error("String_Node_Str");
    throw ClusterConfigException.INVALID_TOPOLOGY_POLICY(clusterConfig.getTopologyPolicy(),"String_Node_Str");
  }
  clusterConfig.setHostToRackMap(hostToRackMap);
  clusterConfig.setTemplateId(templateId);
  if (clusterEntity.getVcRpNames() != null) {
    logger.debug("String_Node_Str");
    String[] rpNames=clusterEntity.getVcRpNameList().toArray(new String[clusterEntity.getVcRpNameList().size()]);
    List<VcCluster> vcClusters=rpMgr.getVcResourcePoolByNameList(rpNames);
    clusterConfig.setVcClusters(vcClusters);
    clusterConfig.setRpNames(clusterEntity.getVcRpNameList());
  }
 else {
    logger.debug("String_Node_Str");
  }
  if (clusterEntity.getVcDatastoreNameList() != null) {
    logger.debug("String_Node_Str");
    Set<String> sharedPattern=datastoreMgr.getSharedDatastoresByNames(clusterEntity.getVcDatastoreNameList());
    clusterConfig.setSharedPattern(sharedPattern);
    Set<String> localPattern=datastoreMgr.getLocalDatastoresByNames(clusterEntity.getVcDatastoreNameList());
    clusterConfig.setLocalPattern(localPattern);
    clusterConfig.setDsNames(clusterEntity.getVcDatastoreNameList());
  }
 else {
    logger.debug("String_Node_Str");
  }
  List<NodeGroupCreate> nodeGroups=new ArrayList<NodeGroupCreate>();
  Set<NodeGroupEntity> nodeGroupEntities=clusterEntity.getNodeGroups();
  long instanceNum=0;
  for (  NodeGroupEntity ngEntity : nodeGroupEntities) {
    NodeGroupCreate group=convertNodeGroups(clusterEntity.getDistro(),ngEntity,clusterEntity.getName());
    nodeGroups.add(group);
    instanceNum+=group.getInstanceNum();
  }
  sortGroups(nodeGroups);
  clusterConfig.setNodeGroups(nodeGroups.toArray(new NodeGroupCreate[nodeGroups.size()]));
  NetworkEntity networkEntity=clusterEntity.getNetwork();
  List<NetworkAdd> networking=new ArrayList<NetworkAdd>();
  NetworkAdd network=new NetworkAdd();
  network.setPortGroup(networkEntity.getPortGroup());
  network.setDhcp(networkEntity.getAllocType() == NetworkEntity.AllocType.DHCP);
  if (!network.isDhcp()) {
    logger.debug("String_Node_Str");
    List<IpBlockEntity> ipBlockEntities=networkMgr.getAllocatedIpBlocks(networkEntity,clusterEntity.getId());
    long allocatedIpNum=IpBlockEntity.count(ipBlockEntities);
    if (allocatedIpNum < instanceNum) {
      long newNum=instanceNum - allocatedIpNum;
      List<IpBlockEntity> newIpBlockEntities=networkMgr.alloc(networkEntity,clusterEntity.getId(),newNum);
      ipBlockEntities.addAll(newIpBlockEntities);
    }
    network.setDns1(networkEntity.getDns1());
    network.setDns2(networkEntity.getDns2());
    network.setGateway(networkEntity.getGateway());
    network.setNetmask(networkEntity.getNetmask());
    List<IpBlock> ips=new ArrayList<IpBlock>();
    for (    IpBlockEntity ipBlockEntity : ipBlockEntities) {
      IpBlock ip=new IpBlock();
      ip.setBeginIp(ipBlockEntity.getBeginAddress());
      ip.setEndIp(ipBlockEntity.getEndAddress());
      ips.add(ip);
    }
    network.setIp(ips);
  }
  networking.add(network);
  clusterConfig.setNetworking(networking);
  clusterConfig.setNetworkName(networkEntity.getName());
  if (clusterEntity.getHadoopConfig() != null) {
    Map hadoopConfig=(new Gson()).fromJson(clusterEntity.getHadoopConfig(),Map.class);
    clusterConfig.setConfiguration((Map<String,Object>)hadoopConfig);
  }
}