Program: 89190
Project: 89190
Buggy source:
@Override @ActionEvent(eventType=EventTypes.EVENT_NETWORK_OFFERING_EDIT,eventDescription="String_Node_Str") public NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd){
  String displayText=cmd.getDisplayText();
  Long id=cmd.getId();
  String name=cmd.getNetworkOfferingName();
  String availabilityStr=cmd.getAvailability();
  Integer sortKey=cmd.getSortKey();
  Availability availability=null;
  String state=cmd.getState();
  UserContext.current().setEventDetails("String_Node_Str" + id);
  NetworkOfferingVO offeringToUpdate=_networkOfferingDao.findById(id);
  if (offeringToUpdate == null) {
    throw new InvalidParameterValueException("String_Node_Str" + id);
  }
  if (offeringToUpdate.isSystemOnly()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  NetworkOfferingVO offering=_networkOfferingDao.createForUpdate(id);
  if (name != null) {
    offering.setName(name);
  }
  if (displayText != null) {
    offering.setDisplayText(displayText);
  }
  if (sortKey != null) {
    offering.setSortKey(sortKey);
  }
  if (state != null) {
    boolean validState=false;
    for (    NetworkOffering.State st : NetworkOffering.State.values()) {
      if (st.name().equalsIgnoreCase(state)) {
        validState=true;
        offering.setState(st);
      }
    }
    if (!validState) {
      throw new InvalidParameterValueException("String_Node_Str" + state);
    }
  }
  if (availabilityStr != null) {
    for (    Availability avlb : Availability.values()) {
      if (avlb.name().equalsIgnoreCase(availabilityStr)) {
        availability=avlb;
      }
    }
    if (availability == null) {
      throw new InvalidParameterValueException("String_Node_Str" + Availability.Required + "String_Node_Str"+ Availability.Optional);
    }
 else {
      if (availability == NetworkOffering.Availability.Required) {
        boolean canOffBeRequired=(offering.getGuestType() == GuestType.Isolated && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(),Service.SourceNat));
        if (!canOffBeRequired) {
          throw new InvalidParameterValueException("String_Node_Str" + NetworkOffering.Availability.Required + "String_Node_Str"+ GuestType.Isolated+ "String_Node_Str"+ Service.SourceNat.getName()+ "String_Node_Str");
        }
        List<NetworkOfferingVO> offerings=_networkOfferingDao.listByAvailability(Availability.Required,false);
        if (!offerings.isEmpty() || offerings.get(0).getId() != offering.getId()) {
          throw new InvalidParameterValueException("String_Node_Str" + offerings.get(0).getId() + "String_Node_Str"+ Availability.Required);
        }
      }
      offering.setAvailability(availability);
    }
  }
  if (_networkOfferingDao.update(id,offering)) {
    return _networkOfferingDao.findById(id);
  }
 else {
    return null;
  }
}

Fixed version (ground truth):
@Override @ActionEvent(eventType=EventTypes.EVENT_NETWORK_OFFERING_EDIT,eventDescription="String_Node_Str") public NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd){
  String displayText=cmd.getDisplayText();
  Long id=cmd.getId();
  String name=cmd.getNetworkOfferingName();
  String availabilityStr=cmd.getAvailability();
  Integer sortKey=cmd.getSortKey();
  Availability availability=null;
  String state=cmd.getState();
  UserContext.current().setEventDetails("String_Node_Str" + id);
  NetworkOfferingVO offeringToUpdate=_networkOfferingDao.findById(id);
  if (offeringToUpdate == null) {
    throw new InvalidParameterValueException("String_Node_Str" + id);
  }
  if (offeringToUpdate.isSystemOnly()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  NetworkOfferingVO offering=_networkOfferingDao.createForUpdate(id);
  if (name != null) {
    offering.setName(name);
  }
  if (displayText != null) {
    offering.setDisplayText(displayText);
  }
  if (sortKey != null) {
    offering.setSortKey(sortKey);
  }
  if (state != null) {
    boolean validState=false;
    for (    NetworkOffering.State st : NetworkOffering.State.values()) {
      if (st.name().equalsIgnoreCase(state)) {
        validState=true;
        offering.setState(st);
      }
    }
    if (!validState) {
      throw new InvalidParameterValueException("String_Node_Str" + state);
    }
  }
  if (availabilityStr != null) {
    for (    Availability avlb : Availability.values()) {
      if (avlb.name().equalsIgnoreCase(availabilityStr)) {
        availability=avlb;
      }
    }
    if (availability == null) {
      throw new InvalidParameterValueException("String_Node_Str" + Availability.Required + "String_Node_Str"+ Availability.Optional);
    }
 else {
      if (availability == NetworkOffering.Availability.Required) {
        boolean canOffBeRequired=(offeringToUpdate.getGuestType() == GuestType.Isolated && _networkMgr.areServicesSupportedByNetworkOffering(offeringToUpdate.getId(),Service.SourceNat));
        if (!canOffBeRequired) {
          throw new InvalidParameterValueException("String_Node_Str" + NetworkOffering.Availability.Required + "String_Node_Str"+ GuestType.Isolated+ "String_Node_Str"+ Service.SourceNat.getName()+ "String_Node_Str");
        }
        List<NetworkOfferingVO> offerings=_networkOfferingDao.listByAvailability(Availability.Required,false);
        if (!offerings.isEmpty() && offerings.get(0).getId() != offeringToUpdate.getId()) {
          throw new InvalidParameterValueException("String_Node_Str" + offerings.get(0).getId() + "String_Node_Str"+ Availability.Required);
        }
      }
      offering.setAvailability(availability);
    }
  }
  if (_networkOfferingDao.update(id,offering)) {
    return _networkOfferingDao.findById(id);
  }
 else {
    return null;
  }
}