Program: 16350
Project: 16350
Buggy source:
/** 
 * Assembly the matched linkages.
 * @param matchedAtomsOfLinkages
 * @param mod
 * @param condition
 * @param ret ModifiedCompound will be stored here.
 */
private void assembleLinkages(List<List<Atom[]>> matchedAtomsOfLinkages,ProteinModification mod,List<ModifiedCompound> ret){
  ModificationCondition condition=mod.getCondition();
  List<ModificationLinkage> modLinks=condition.getLinkages();
  int nLink=matchedAtomsOfLinkages.size();
  int[] indices=new int[nLink];
  Set<ModifiedCompound> identifiedCompounds=new HashSet<ModifiedCompound>();
  while (indices[0] < matchedAtomsOfLinkages.get(0).size()) {
    List<Atom[]> atomLinkages=new ArrayList<Atom[]>(nLink);
    for (int iLink=0; iLink < nLink; iLink++) {
      Atom[] atoms=matchedAtomsOfLinkages.get(iLink).get(indices[iLink]);
      atomLinkages.add(atoms);
    }
    if (matchLinkages(modLinks,atomLinkages)) {
      int n=atomLinkages.size();
      List<StructureAtomLinkage> linkages=new ArrayList<StructureAtomLinkage>(n);
      for (int i=0; i < n; i++) {
        Atom[] linkage=atomLinkages.get(i);
        StructureAtomLinkage link=StructureUtil.getStructureAtomLinkage(linkage[0],residues.contains(linkage[0].getGroup()),linkage[1],residues.contains(linkage[1].getGroup()));
        linkages.add(link);
      }
      ModifiedCompound mc=new ModifiedCompoundImpl(mod,linkages);
      if (!identifiedCompounds.contains(mc)) {
        ret.add(mc);
        identifiedCompounds.add(mc);
      }
    }
    int i=nLink - 1;
    while (i >= 0) {
      if (i == 0 || indices[i] < matchedAtomsOfLinkages.get(i).size() - 1) {
        indices[i]++;
        break;
      }
 else {
        indices[i]=0;
        i--;
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Assembly the matched linkages
 * @param matchedAtomsOfLinkages
 * @param mod
 * @param ret ModifiedCompound will be stored here
 */
private void assembleLinkages(List<List<Atom[]>> matchedAtomsOfLinkages,ProteinModification mod,List<ModifiedCompound> ret){
  ModificationCondition condition=mod.getCondition();
  List<ModificationLinkage> modLinks=condition.getLinkages();
  int nLink=matchedAtomsOfLinkages.size();
  int[] indices=new int[nLink];
  Set<ModifiedCompound> identifiedCompounds=new HashSet<ModifiedCompound>();
  while (indices[0] < matchedAtomsOfLinkages.get(0).size()) {
    List<Atom[]> atomLinkages=new ArrayList<Atom[]>(nLink);
    for (int iLink=0; iLink < nLink; iLink++) {
      Atom[] atoms=matchedAtomsOfLinkages.get(iLink).get(indices[iLink]);
      atomLinkages.add(atoms);
    }
    if (matchLinkages(modLinks,atomLinkages)) {
      int n=atomLinkages.size();
      List<StructureAtomLinkage> linkages=new ArrayList<StructureAtomLinkage>(n);
      for (int i=0; i < n; i++) {
        Atom[] linkage=atomLinkages.get(i);
        StructureAtomLinkage link=StructureUtil.getStructureAtomLinkage(linkage[0],residues.contains(linkage[0].getGroup()),linkage[1],residues.contains(linkage[1].getGroup()));
        linkages.add(link);
      }
      ModifiedCompound mc=new ModifiedCompoundImpl(mod,linkages);
      if (!identifiedCompounds.contains(mc)) {
        ret.add(mc);
        identifiedCompounds.add(mc);
      }
    }
    int i=nLink - 1;
    while (i >= 0) {
      if (i == 0 || indices[i] < matchedAtomsOfLinkages.get(i).size() - 1) {
        indices[i]++;
        break;
      }
 else {
        indices[i]=0;
        i--;
      }
    }
  }
}