Program: 105948
Project: 105948
Buggy source:
private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd){
  int i=0;
  String[] results=new String[cmd.getIpAddresses().length];
  VmwareContext context=getServiceContext();
  try {
    VmwareHypervisorHost hyperHost=getHyperHost(context);
    IpAddressTO[] ips=cmd.getIpAddresses();
    String routerName=cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    String controlIp=VmwareResource.getRouterSshControlIp(cmd);
    VirtualMachineMO vmMo=hyperHost.findVmOnHyperHost(routerName);
    if (vmMo == null) {
      if (hyperHost instanceof HostMO) {
        ClusterMO clusterMo=new ClusterMO(hyperHost.getContext(),((HostMO)hyperHost).getParentMor());
        vmMo=clusterMo.findVmOnHyperHost(routerName);
      }
    }
    if (vmMo == null) {
      String msg="String_Node_Str" + routerName + "String_Node_Str";
      s_logger.error(msg);
      throw new Exception(msg);
    }
    for (    IpAddressTO ip : ips) {
      URI broadcastUri=BroadcastDomainType.fromString(ip.getBroadcastUri());
      if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
        throw new InternalErrorException("String_Node_Str" + ip.getBroadcastUri());
      }
      String vlanId=BroadcastDomainType.getValue(broadcastUri);
      String publicNeworkName=HypervisorHostHelper.getPublicNetworkNamePrefix(vlanId);
      Pair<Integer,VirtualDevice> publicNicInfo=vmMo.getNicDeviceIndex(publicNeworkName);
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + publicNeworkName + "String_Node_Str"+ publicNicInfo.first());
      }
      boolean addVif=false;
      if (ip.isAdd() && publicNicInfo.first().intValue() == -1) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + controlIp + "String_Node_Str"+ ip.getPublicIp());
        }
        addVif=true;
      }
      if (addVif) {
        plugPublicNic(vmMo,vlanId,ip.getVifMacAddress());
        publicNicInfo=vmMo.getNicDeviceIndex(publicNeworkName);
        if (publicNicInfo.first().intValue() >= 0) {
          networkUsage(controlIp,"String_Node_Str","String_Node_Str" + publicNicInfo.first());
        }
      }
      if (publicNicInfo.first().intValue() < 0) {
        String msg="String_Node_Str";
        s_logger.error(msg);
        throw new InternalErrorException(msg);
      }
      ip.setNicDevId(publicNicInfo.first().intValue());
      ip.setNewNic(addVif);
    }
  }
 catch (  Throwable e) {
    s_logger.error("String_Node_Str" + e.toString() + "String_Node_Str",e);
    return new ExecutionResult(false,e.toString());
  }
  return new ExecutionResult(true,null);
}

Fixed version (ground truth):
private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd){
  VmwareContext context=getServiceContext();
  try {
    VmwareHypervisorHost hyperHost=getHyperHost(context);
    IpAddressTO[] ips=cmd.getIpAddresses();
    String routerName=cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    String controlIp=VmwareResource.getRouterSshControlIp(cmd);
    VirtualMachineMO vmMo=hyperHost.findVmOnHyperHost(routerName);
    if (vmMo == null) {
      if (hyperHost instanceof HostMO) {
        ClusterMO clusterMo=new ClusterMO(hyperHost.getContext(),((HostMO)hyperHost).getParentMor());
        vmMo=clusterMo.findVmOnHyperHost(routerName);
      }
    }
    if (vmMo == null) {
      String msg="String_Node_Str" + routerName + "String_Node_Str";
      s_logger.error(msg);
      throw new Exception(msg);
    }
    for (    IpAddressTO ip : ips) {
      URI broadcastUri=BroadcastDomainType.fromString(ip.getBroadcastUri());
      if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
        throw new InternalErrorException("String_Node_Str" + ip.getBroadcastUri());
      }
      String vlanId=BroadcastDomainType.getValue(broadcastUri);
      String publicNeworkName=HypervisorHostHelper.getPublicNetworkNamePrefix(vlanId);
      Pair<Integer,VirtualDevice> publicNicInfo=vmMo.getNicDeviceIndex(publicNeworkName);
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + publicNeworkName + "String_Node_Str"+ publicNicInfo.first());
      }
      boolean addVif=false;
      if (ip.isAdd() && publicNicInfo.first().intValue() == -1) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + controlIp + "String_Node_Str"+ ip.getPublicIp());
        }
        addVif=true;
      }
      if (addVif) {
        plugPublicNic(vmMo,vlanId,ip.getVifMacAddress());
        publicNicInfo=vmMo.getNicDeviceIndex(publicNeworkName);
        if (publicNicInfo.first().intValue() >= 0) {
          networkUsage(controlIp,"String_Node_Str","String_Node_Str" + publicNicInfo.first());
        }
      }
      if (publicNicInfo.first().intValue() < 0) {
        String msg="String_Node_Str";
        s_logger.error(msg);
        throw new InternalErrorException(msg);
      }
      ip.setNicDevId(publicNicInfo.first().intValue());
      ip.setNewNic(addVif);
    }
  }
 catch (  Throwable e) {
    s_logger.error("String_Node_Str" + e.toString() + "String_Node_Str",e);
    return new ExecutionResult(false,e.toString());
  }
  return new ExecutionResult(true,null);
}