Program: 34436
Project: 34436
Buggy source:
@VisibleForTesting public synchronized SelectionResult select(ResourceDescriptor requestResource,String requestNodeLabel,String requestNodeGpuType,int startStatesTaskCount,List<ValueRange> reusePorts,Map<String,NodeConfiguration> configuredNodes) throws NotAvailableException {
  LOGGER.logInfo("String_Node_Str",requestResource,requestNodeLabel,requestNodeGpuType,startStatesTaskCount,ValueRangeUtils.toString(reusePorts));
  initFilteredNodes();
  filterNodesByNodeLabel(requestNodeLabel);
  filterNodesByGpuType(configuredNodes,requestNodeGpuType);
  if (!conf.getAmAllowNoneGpuJobOnGpuNode()) {
    int jobTotalRequestGpu=requestManager.getTotalGpuCount();
    filterNodesForNoneGpuJob(jobTotalRequestGpu);
  }
  ResourceDescriptor optimizedRequestResource=YamlUtils.deepCopy(requestResource,ResourceDescriptor.class);
  if (ValueRangeUtils.getValueNumber(reusePorts) > 0) {
    LOGGER.logInfo("String_Node_Str",ValueRangeUtils.toString(reusePorts));
    optimizedRequestResource.setPortRanges(reusePorts);
  }
  filterNodesByResource(optimizedRequestResource,conf.getAmSkipLocalTriedResource());
  filterNodesByRackSelectionPolicy(optimizedRequestResource,startStatesTaskCount);
  if (filteredNodes.size() < 1) {
    if (requestNodeGpuType != null || requestResource.getPortNumber() > 0) {
      throw new NotAvailableException(String.format("String_Node_Str",optimizedRequestResource,requestNodeGpuType,requestNodeLabel));
    }
  }
  SelectionResult selectionResult=selectNodes(optimizedRequestResource,startStatesTaskCount);
  List<ValueRange> portRanges=selectPorts(selectionResult,optimizedRequestResource);
  optimizedRequestResource.setPortRanges(portRanges);
  selectionResult.setOptimizedResource(optimizedRequestResource);
  return selectionResult;
}

Fixed version (ground truth):
@VisibleForTesting public synchronized SelectionResult select(ResourceDescriptor requestResource,String requestNodeLabel,String requestNodeGpuType,int startStatesTaskCount,List<ValueRange> reusePorts,Map<String,NodeConfiguration> configuredNodes) throws NotAvailableException {
  LOGGER.logInfo("String_Node_Str",requestResource,requestNodeLabel,requestNodeGpuType,startStatesTaskCount,ValueRangeUtils.toString(reusePorts));
  initFilteredNodes();
  filterNodesByNodeLabel(requestNodeLabel);
  filterNodesByGpuType(configuredNodes,requestNodeGpuType);
  if (!conf.getAmAllowNoneGpuJobOnGpuNode()) {
    int jobTotalRequestGpu=requestManager.getTotalGpuCount();
    filterNodesForNoneGpuJob(jobTotalRequestGpu);
  }
  ResourceDescriptor optimizedRequestResource=YamlUtils.deepCopy(requestResource,ResourceDescriptor.class);
  if (ValueRangeUtils.getValueNumber(reusePorts) > 0) {
    LOGGER.logInfo("String_Node_Str",ValueRangeUtils.toString(reusePorts));
    optimizedRequestResource.setPortRanges(reusePorts);
  }
  if (optimizedRequestResource.getPortNumber() > 0 && ValueRangeUtils.getValueNumber(optimizedRequestResource.getPortRanges()) <= 0) {
    List<ValueRange> portRanges=selectPortsFromFilteredNodes(optimizedRequestResource);
    LOGGER.logInfo("String_Node_Str",ValueRangeUtils.toString(portRanges));
    if (ValueRangeUtils.getValueNumber(portRanges) == optimizedRequestResource.getPortNumber()) {
      optimizedRequestResource.setPortRanges(portRanges);
    }
  }
  filterNodesByResource(optimizedRequestResource,conf.getAmSkipLocalTriedResource());
  filterNodesByRackSelectionPolicy(optimizedRequestResource,startStatesTaskCount);
  if (filteredNodes.size() < 1) {
    if (requestNodeGpuType != null) {
      throw new NotAvailableException(String.format("String_Node_Str",optimizedRequestResource,requestNodeGpuType,requestNodeLabel));
    }
    if (optimizedRequestResource.getPortNumber() > 0 && ValueRangeUtils.getValueNumber(optimizedRequestResource.getPortRanges()) <= 0) {
      throw new NotAvailableException(String.format("String_Node_Str",optimizedRequestResource,requestNodeGpuType,requestNodeLabel));
    }
  }
  SelectionResult selectionResult=selectNodes(optimizedRequestResource,startStatesTaskCount);
  List<ValueRange> portRanges=selectPorts(selectionResult,optimizedRequestResource);
  optimizedRequestResource.setPortRanges(portRanges);
  selectionResult.setOptimizedResource(optimizedRequestResource);
  return selectionResult;
}