Program: 25498
Project: 25498
Buggy source:
public void deriveAndSaveSortedNeighborPairs() throws IOException, InterruptedException {
  LOG.info("String_Node_Str");
  final String renderParametersUrlTemplate=getRenderParametersUrlTemplate();
  final List<Double> zValues=getZValues();
  final ExistingMatchHelper existingMatchHelper;
  if (parameters.excludePairsInMatchCollection == null) {
    existingMatchHelper=null;
  }
 else {
    existingMatchHelper=new ExistingMatchHelper(parameters,renderDataClient);
  }
  final Map<Double,TileBoundsRTree> zToTreeMap=new LinkedHashMap<>(zValues.size());
  double z;
  for (int zIndex=0; (zIndex < zValues.size()) && (zIndex < parameters.zNeighborDistance); zIndex++) {
    z=zValues.get(zIndex);
    zToTreeMap.put(z,buildRTree(z));
    if (existingMatchHelper != null) {
      existingMatchHelper.addExistingPairs(z);
    }
  }
  final Set<OrderedCanvasIdPair> neighborPairs=new TreeSet<>();
  int totalSavedPairCount=0;
  Double neighborZ;
  TileBoundsRTree currentZTree;
  List<TileBoundsRTree> neighborTreeList;
  Set<OrderedCanvasIdPair> currentNeighborPairs;
  for (int zIndex=0; zIndex < zValues.size(); zIndex++) {
    z=zValues.get(zIndex);
    if (parameters.zNeighborDistance == 0) {
      zToTreeMap.put(z,buildRTree(z));
    }
    double maxNeighborZ=z;
    final double idealMaxNeighborZ=Math.min(parameters.maxZ,z + parameters.zNeighborDistance);
    for (int neighborZIndex=zIndex + 1; neighborZIndex < zValues.size(); neighborZIndex++) {
      maxNeighborZ=zValues.get(neighborZIndex);
      if (maxNeighborZ > idealMaxNeighborZ) {
        maxNeighborZ=zValues.get(neighborZIndex - 1);
        break;
      }
    }
    if (!zToTreeMap.containsKey(maxNeighborZ)) {
      if (zIndex > 0) {
        final double completedZ=zValues.get(zIndex - 1);
        zToTreeMap.remove(completedZ);
      }
      zToTreeMap.put(maxNeighborZ,buildRTree(maxNeighborZ));
      if (existingMatchHelper != null) {
        existingMatchHelper.addExistingPairs(maxNeighborZ);
      }
    }
    currentZTree=zToTreeMap.get(z);
    neighborTreeList=new ArrayList<>();
    for (int neighborZIndex=zIndex + 1; neighborZIndex < zValues.size(); neighborZIndex++) {
      neighborZ=zValues.get(neighborZIndex);
      if (neighborZ > maxNeighborZ) {
        break;
      }
      neighborTreeList.add(zToTreeMap.get(neighborZ));
    }
    currentNeighborPairs=currentZTree.getCircleNeighbors(neighborTreeList,parameters.xyNeighborFactor,parameters.explicitRadius,parameters.excludeCornerNeighbors,parameters.excludeSameLayerNeighbors,parameters.excludeSameSectionNeighbors);
    if (existingMatchHelper != null) {
      existingMatchHelper.removeExistingPairs(z,currentNeighborPairs);
    }
    neighborPairs.addAll(currentNeighborPairs);
    if (neighborPairs.size() > parameters.maxPairsPerFile) {
      final List<OrderedCanvasIdPair> neighborPairsList=new ArrayList<>(neighborPairs);
      int fromIndex=0;
      for (; ; fromIndex+=parameters.maxPairsPerFile) {
        final int toIndex=fromIndex + parameters.maxPairsPerFile;
        if (toIndex <= neighborPairs.size()) {
          savePairs(neighborPairsList.subList(fromIndex,toIndex),renderParametersUrlTemplate,getOutputFileName());
          numberOfOutputFiles++;
          totalSavedPairCount+=parameters.maxPairsPerFile;
        }
 else {
          break;
        }
      }
      neighborPairs.clear();
      neighborPairs.addAll(neighborPairsList.subList(fromIndex,neighborPairsList.size()));
    }
  }
  if (neighborPairs.size() > 0) {
    final List<OrderedCanvasIdPair> neighborPairsList=new ArrayList<>(neighborPairs);
    final String outputFileName=numberOfOutputFiles == 0 ? parameters.toJson : getOutputFileName();
    savePairs(neighborPairsList,renderParametersUrlTemplate,outputFileName);
    totalSavedPairCount+=neighborPairs.size();
  }
  LOG.info("String_Node_Str",totalSavedPairCount);
}

Fixed version (ground truth):
public void deriveAndSaveSortedNeighborPairs() throws IOException, InterruptedException {
  LOG.info("String_Node_Str");
  final String renderParametersUrlTemplate=getRenderParametersUrlTemplate();
  final List<Double> zValues=getZValues();
  final ExistingMatchHelper existingMatchHelper;
  if (parameters.excludePairsInMatchCollection == null) {
    existingMatchHelper=null;
  }
 else {
    existingMatchHelper=new ExistingMatchHelper(parameters,renderDataClient);
  }
  final Map<Double,TileBoundsRTree> zToTreeMap=new LinkedHashMap<>(zValues.size());
  double z;
  for (int zIndex=0; (zIndex < zValues.size()) && (zIndex < parameters.zNeighborDistance); zIndex++) {
    z=zValues.get(zIndex);
    zToTreeMap.put(z,buildRTree(z));
    if (existingMatchHelper != null) {
      existingMatchHelper.addExistingPairs(z);
    }
  }
  final Set<OrderedCanvasIdPair> neighborPairs=new TreeSet<>();
  int totalSavedPairCount=0;
  Double neighborZ;
  TileBoundsRTree currentZTree;
  List<TileBoundsRTree> neighborTreeList;
  Set<OrderedCanvasIdPair> currentNeighborPairs;
  for (int zIndex=0; zIndex < zValues.size(); zIndex++) {
    z=zValues.get(zIndex);
    if (parameters.zNeighborDistance == 0) {
      zToTreeMap.put(z,buildRTree(z));
    }
    neighborTreeList=new ArrayList<>();
    final double idealMaxNeighborZ=Math.min(parameters.maxZ,z + parameters.zNeighborDistance);
    for (int neighborZIndex=zIndex + 1; neighborZIndex < zValues.size(); neighborZIndex++) {
      neighborZ=zValues.get(neighborZIndex);
      if (neighborZ > idealMaxNeighborZ) {
        break;
      }
      if (!zToTreeMap.containsKey(neighborZ)) {
        if (zIndex > 0) {
          final double completedZ=zValues.get(zIndex - 1);
          zToTreeMap.remove(completedZ);
        }
        zToTreeMap.put(neighborZ,buildRTree(neighborZ));
        if (existingMatchHelper != null) {
          existingMatchHelper.addExistingPairs(neighborZ);
        }
      }
      neighborTreeList.add(zToTreeMap.get(neighborZ));
    }
    currentZTree=zToTreeMap.get(z);
    currentNeighborPairs=currentZTree.getCircleNeighbors(neighborTreeList,parameters.xyNeighborFactor,parameters.explicitRadius,parameters.excludeCornerNeighbors,parameters.excludeSameLayerNeighbors,parameters.excludeSameSectionNeighbors);
    if (existingMatchHelper != null) {
      existingMatchHelper.removeExistingPairs(z,currentNeighborPairs);
    }
    neighborPairs.addAll(currentNeighborPairs);
    if (neighborPairs.size() > parameters.maxPairsPerFile) {
      final List<OrderedCanvasIdPair> neighborPairsList=new ArrayList<>(neighborPairs);
      int fromIndex=0;
      for (; ; fromIndex+=parameters.maxPairsPerFile) {
        final int toIndex=fromIndex + parameters.maxPairsPerFile;
        if (toIndex <= neighborPairs.size()) {
          savePairs(neighborPairsList.subList(fromIndex,toIndex),renderParametersUrlTemplate,getOutputFileName());
          numberOfOutputFiles++;
          totalSavedPairCount+=parameters.maxPairsPerFile;
        }
 else {
          break;
        }
      }
      neighborPairs.clear();
      neighborPairs.addAll(neighborPairsList.subList(fromIndex,neighborPairsList.size()));
    }
  }
  if (neighborPairs.size() > 0) {
    final List<OrderedCanvasIdPair> neighborPairsList=new ArrayList<>(neighborPairs);
    final String outputFileName=numberOfOutputFiles == 0 ? parameters.toJson : getOutputFileName();
    savePairs(neighborPairsList,renderParametersUrlTemplate,outputFileName);
    totalSavedPairCount+=neighborPairs.size();
  }
  LOG.info("String_Node_Str",totalSavedPairCount);
}