Program: 110849
Project: 110849
Buggy source:
/** 
 * Finds Artifact prefix conflicts between generated artifacts. An artifact prefix conflict happens if one action generates an artifact whose path is a prefix of another artifact's path. Those two artifacts cannot exist simultaneously in the output tree.
 * @param actionGraph the {@link ActionGraph} to query for artifact conflicts
 * @param artifactPathMap a map mapping generated artifacts to their exec paths
 * @return A map between actions that generated the conflicting artifacts and their associated{@link ArtifactPrefixConflictException}.
 */
public static Map<ActionAnalysisMetadata,ArtifactPrefixConflictException> findArtifactPrefixConflicts(ActionGraph actionGraph,SortedMap<PathFragment,Artifact> artifactPathMap){
  if (artifactPathMap.isEmpty()) {
    return ImmutableMap.<ActionAnalysisMetadata,ArtifactPrefixConflictException>of();
  }
  Map<ActionAnalysisMetadata,ArtifactPrefixConflictException> badActions=new LinkedHashMap();
  Iterator<PathFragment> iter=artifactPathMap.keySet().iterator();
  for (PathFragment pathJ=iter.next(); iter.hasNext(); ) {
    PathFragment pathI=pathJ;
    while (iter.hasNext()) {
      pathJ=iter.next();
      if (pathJ.startsWith(pathI)) {
        Artifact artifactI=Preconditions.checkNotNull(artifactPathMap.get(pathI),pathI);
        Artifact artifactJ=Preconditions.checkNotNull(artifactPathMap.get(pathJ),pathJ);
        ActionAnalysisMetadata actionI=Preconditions.checkNotNull(actionGraph.getGeneratingAction(artifactI),artifactI);
        ActionAnalysisMetadata actionJ=Preconditions.checkNotNull(actionGraph.getGeneratingAction(artifactJ),artifactJ);
        if (actionI.shouldReportPathPrefixConflict(actionJ)) {
          ArtifactPrefixConflictException exception=new ArtifactPrefixConflictException(pathI,pathJ,actionI.getOwner().getLabel(),actionJ.getOwner().getLabel());
          badActions.put(actionI,exception);
          badActions.put(actionJ,exception);
        }
      }
 else {
        break;
      }
    }
  }
  return ImmutableMap.copyOf(badActions);
}

Fixed version (ground truth):
/** 
 * Finds Artifact prefix conflicts between generated artifacts. An artifact prefix conflict happens if one action generates an artifact whose path is a prefix of another artifact's path. Those two artifacts cannot exist simultaneously in the output tree.
 * @param actionGraph the {@link ActionGraph} to query for artifact conflicts
 * @param artifactPathMap a map mapping generated artifacts to their exec paths
 * @return A map between actions that generated the conflicting artifacts and their associated{@link ArtifactPrefixConflictException}.
 */
public static Map<ActionAnalysisMetadata,ArtifactPrefixConflictException> findArtifactPrefixConflicts(ActionGraph actionGraph,SortedMap<PathFragment,Artifact> artifactPathMap){
  if (artifactPathMap.isEmpty()) {
    return ImmutableMap.<ActionAnalysisMetadata,ArtifactPrefixConflictException>of();
  }
  Map<ActionAnalysisMetadata,ArtifactPrefixConflictException> badActions=new LinkedHashMap();
  Iterator<PathFragment> iter=artifactPathMap.keySet().iterator();
  for (PathFragment pathJ=iter.next(); iter.hasNext(); ) {
    PathFragment pathI=pathJ;
    while (iter.hasNext()) {
      pathJ=iter.next();
      if (pathJ.startsWith(pathI)) {
        Artifact artifactI=Preconditions.checkNotNull(artifactPathMap.get(pathI),pathI);
        Artifact artifactJ=Preconditions.checkNotNull(artifactPathMap.get(pathJ),pathJ);
        if (artifactJ.hasParent() && artifactJ.getParent().equals(artifactI)) {
          continue;
        }
        ActionAnalysisMetadata actionI=Preconditions.checkNotNull(actionGraph.getGeneratingAction(artifactI),artifactI);
        ActionAnalysisMetadata actionJ=Preconditions.checkNotNull(actionGraph.getGeneratingAction(artifactJ),artifactJ);
        if (actionI.shouldReportPathPrefixConflict(actionJ)) {
          ArtifactPrefixConflictException exception=new ArtifactPrefixConflictException(pathI,pathJ,actionI.getOwner().getLabel(),actionJ.getOwner().getLabel());
          badActions.put(actionI,exception);
          badActions.put(actionJ,exception);
        }
      }
 else {
        break;
      }
    }
  }
  return ImmutableMap.copyOf(badActions);
}