Program: 106364
Project: 106364
Buggy source:
public static Pair<ManagedObjectReference,String> prepareNetwork(String vSwitchName,String namePrefix,HostMO hostMo,String vlanId,Integer networkRateMbps,Integer networkRateMulticastMbps,long timeOutMs,boolean syncPeerHosts) throws Exception {
  HostVirtualSwitch vSwitch;
  vSwitch=hostMo.getHostVirtualSwitchByName(vSwitchName);
  if (vSwitch == null) {
    String msg="String_Node_Str" + vSwitchName;
    s_logger.error(msg);
    throw new Exception(msg);
  }
  boolean createGCTag=false;
  String networkName;
  Integer vid=null;
  if (vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
    createGCTag=true;
    vid=Integer.parseInt(vlanId);
  }
  networkName=composeCloudNetworkName(namePrefix,vlanId,networkRateMbps,vSwitchName);
  HostNetworkSecurityPolicy secPolicy=null;
  if (namePrefix.equalsIgnoreCase("String_Node_Str")) {
    secPolicy=new HostNetworkSecurityPolicy();
    secPolicy.setAllowPromiscuous(Boolean.TRUE);
    secPolicy.setForgedTransmits(Boolean.TRUE);
    secPolicy.setMacChanges(Boolean.TRUE);
  }
  HostNetworkTrafficShapingPolicy shapingPolicy=null;
  if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
    shapingPolicy=new HostNetworkTrafficShapingPolicy();
    shapingPolicy.setEnabled(true);
    shapingPolicy.setAverageBandwidth((long)networkRateMbps.intValue() * 1024L * 1024L);
    shapingPolicy.setPeakBandwidth((long)(shapingPolicy.getAverageBandwidth() * 1.5));
    shapingPolicy.setBurstSize(5 * shapingPolicy.getAverageBandwidth() / 8);
  }
  boolean bWaitPortGroupReady=false;
  if (!hostMo.hasPortGroup(vSwitch,networkName)) {
    hostMo.createPortGroup(vSwitch,networkName,vid,secPolicy,shapingPolicy);
    bWaitPortGroupReady=true;
  }
 else {
    HostPortGroupSpec spec=hostMo.getPortGroupSpec(networkName);
    if (!isSpecMatch(spec,vid,shapingPolicy)) {
      hostMo.updatePortGroup(vSwitch,networkName,vid,secPolicy,shapingPolicy);
      bWaitPortGroupReady=true;
    }
  }
  ManagedObjectReference morNetwork;
  if (bWaitPortGroupReady)   morNetwork=waitForNetworkReady(hostMo,networkName,timeOutMs);
 else   morNetwork=hostMo.getNetworkMor(networkName);
  if (morNetwork == null) {
    String msg="String_Node_Str" + networkName;
    s_logger.error(msg);
    throw new Exception(msg);
  }
  if (createGCTag) {
    NetworkMO networkMo=new NetworkMO(hostMo.getContext(),morNetwork);
    networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC,"String_Node_Str");
  }
  if (syncPeerHosts) {
    ManagedObjectReference morParent=hostMo.getParentMor();
    if (morParent != null && morParent.getType().equals("String_Node_Str")) {
      GlobalLock lock=GlobalLock.getInternLock("String_Node_Str" + morParent.getValue());
      try {
        if (lock.lock(DEFAULT_LOCK_TIMEOUT_SECONDS)) {
          try {
            ManagedObjectReference[] hosts=(ManagedObjectReference[])hostMo.getContext().getVimClient().getDynamicProperty(morParent,"String_Node_Str");
            if (hosts != null) {
              for (              ManagedObjectReference otherHost : hosts) {
                if (!otherHost.getValue().equals(hostMo.getMor().getValue())) {
                  HostMO otherHostMo=new HostMO(hostMo.getContext(),otherHost);
                  try {
                    if (s_logger.isDebugEnabled())                     s_logger.debug("String_Node_Str" + vlanId + "String_Node_Str"+ otherHostMo.getHostName());
                    prepareNetwork(vSwitchName,namePrefix,otherHostMo,vlanId,networkRateMbps,networkRateMulticastMbps,timeOutMs,false);
                  }
 catch (                  Exception e) {
                    s_logger.warn("String_Node_Str" + vlanId + "String_Node_Str"+ otherHostMo.getHostName());
                  }
                }
              }
            }
          }
  finally {
            lock.unlock();
          }
        }
 else {
          s_logger.warn("String_Node_Str" + vlanId);
        }
      }
  finally {
        lock.releaseRef();
      }
    }
  }
  s_logger.info("String_Node_Str" + networkName + "String_Node_Str"+ vSwitchName);
  return new Pair<ManagedObjectReference,String>(morNetwork,networkName);
}

Fixed version (ground truth):
public static Pair<ManagedObjectReference,String> prepareNetwork(String vSwitchName,String namePrefix,HostMO hostMo,String vlanId,Integer networkRateMbps,Integer networkRateMulticastMbps,long timeOutMs,boolean syncPeerHosts) throws Exception {
  HostVirtualSwitch vSwitch;
  vSwitch=hostMo.getHostVirtualSwitchByName(vSwitchName);
  if (vSwitch == null) {
    String msg="String_Node_Str" + vSwitchName;
    s_logger.error(msg);
    throw new Exception(msg);
  }
  boolean createGCTag=false;
  String networkName;
  Integer vid=null;
  if (vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
    createGCTag=true;
    vid=Integer.parseInt(vlanId);
  }
  networkName=composeCloudNetworkName(namePrefix,vlanId,networkRateMbps,vSwitchName);
  HostNetworkSecurityPolicy secPolicy=null;
  if (namePrefix.equalsIgnoreCase("String_Node_Str")) {
    secPolicy=new HostNetworkSecurityPolicy();
    secPolicy.setAllowPromiscuous(Boolean.TRUE);
    secPolicy.setForgedTransmits(Boolean.TRUE);
    secPolicy.setMacChanges(Boolean.TRUE);
  }
  HostNetworkTrafficShapingPolicy shapingPolicy=null;
  if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
    shapingPolicy=new HostNetworkTrafficShapingPolicy();
    shapingPolicy.setEnabled(true);
    shapingPolicy.setAverageBandwidth((long)networkRateMbps.intValue() * 1024L * 1024L);
    shapingPolicy.setPeakBandwidth((long)(shapingPolicy.getAverageBandwidth() * 1.5));
    shapingPolicy.setBurstSize(5 * shapingPolicy.getAverageBandwidth() / 8);
  }
  boolean bWaitPortGroupReady=false;
  if (!hostMo.hasPortGroup(vSwitch,networkName)) {
    hostMo.createPortGroup(vSwitch,networkName,vid,secPolicy,shapingPolicy);
    bWaitPortGroupReady=true;
  }
 else {
    HostPortGroupSpec spec=hostMo.getPortGroupSpec(networkName);
    if (!isSpecMatch(spec,vid,shapingPolicy)) {
      hostMo.updatePortGroup(vSwitch,networkName,vid,secPolicy,shapingPolicy);
      bWaitPortGroupReady=true;
    }
  }
  ManagedObjectReference morNetwork;
  if (bWaitPortGroupReady)   morNetwork=waitForNetworkReady(hostMo,networkName,timeOutMs);
 else   morNetwork=hostMo.getNetworkMor(networkName);
  if (morNetwork == null) {
    String msg="String_Node_Str" + networkName;
    s_logger.error(msg);
    throw new Exception(msg);
  }
  if (createGCTag) {
    NetworkMO networkMo=new NetworkMO(hostMo.getContext(),morNetwork);
    networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC,"String_Node_Str");
  }
  if (syncPeerHosts) {
    ManagedObjectReference morParent=hostMo.getParentMor();
    if (morParent != null && morParent.getType().equals("String_Node_Str")) {
      GlobalLock lock=GlobalLock.getInternLock("String_Node_Str" + morParent.getValue());
      try {
        if (lock.lock(DEFAULT_LOCK_TIMEOUT_SECONDS)) {
          try {
            List<ManagedObjectReference> hosts=(List<ManagedObjectReference>)hostMo.getContext().getVimClient().getDynamicProperty(morParent,"String_Node_Str");
            if (hosts != null) {
              for (              ManagedObjectReference otherHost : hosts) {
                if (!otherHost.getValue().equals(hostMo.getMor().getValue())) {
                  HostMO otherHostMo=new HostMO(hostMo.getContext(),otherHost);
                  try {
                    if (s_logger.isDebugEnabled())                     s_logger.debug("String_Node_Str" + vlanId + "String_Node_Str"+ otherHostMo.getHostName());
                    prepareNetwork(vSwitchName,namePrefix,otherHostMo,vlanId,networkRateMbps,networkRateMulticastMbps,timeOutMs,false);
                  }
 catch (                  Exception e) {
                    s_logger.warn("String_Node_Str" + vlanId + "String_Node_Str"+ otherHostMo.getHostName());
                  }
                }
              }
            }
          }
  finally {
            lock.unlock();
          }
        }
 else {
          s_logger.warn("String_Node_Str" + vlanId);
        }
      }
  finally {
        lock.releaseRef();
      }
    }
  }
  s_logger.info("String_Node_Str" + networkName + "String_Node_Str"+ vSwitchName);
  return new Pair<ManagedObjectReference,String>(morNetwork,networkName);
}