Program: 17125
Project: 17125
Buggy source:
/** 
 * Parse chemically modified residues in a structure.
 * @param structure query {@link Structure}.
 * @param potentialModifications query {@link ProteinModification}s.
 * @param modelnr model number.
 * @return an list of {@link ModifiedCompound}s, or null if the nodelnr is larger than the number of models in the structure.
 * @throws IllegalArgumentException if null structure, or null or empty potentialModifications, or potentialModifications contain  modifications other than ModifiedResidues.
 */
@Override public List<ModifiedCompound> parse(final Structure structure,final Set<ProteinModification> potentialModifications,final int modelnr){
  if (structure == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (potentialModifications == null || potentialModifications.isEmpty()) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  for (  ProteinModification mod : potentialModifications) {
    if (mod.getCategory() != ModificationCategory.CHEMICAL_MODIFICATION) {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  if (modelnr >= structure.nrModels())   return null;
  List<ModifiedCompound> ret=new ArrayList<ModifiedCompound>();
  List<Chain> chains=structure.getChains(modelnr);
  for (  Chain chain : chains) {
    List<Group> residues=chain.getSeqResGroups();
    int sizeRes=residues.size();
    for (int iRes=0; iRes < sizeRes; iRes++) {
      Group residue=residues.get(iRes);
      String pdbccId=residue.getPDBName();
      ProteinModification mod=ProteinModification.getByPdbccId(pdbccId);
      if (mod == null || !potentialModifications.contains(mod)) {
        continue;
      }
      ModificationCondition condition=mod.getCondition();
      Component comp=condition.getComponents().get(0);
      if ((comp.isNTerminal() && iRes == 0) || (comp.isCTerminal() && iRes == sizeRes - 1)) {
        continue;
      }
      ModifiedCompound modRes=ModifiedCompoundFactory.createModifiedResidue(mod,residue);
      ret.add(modRes);
    }
  }
  return ret;
}

Fixed version (ground truth):
/** 
 * Parse chemically modified residues in a structure.
 * @param structure query {@link Structure}.
 * @param potentialModifications query {@link ProteinModification}s.
 * @param modelnr model number.
 * @return an list of {@link ModifiedCompound}s, or null if the nodelnr is larger than the number of models in the structure.
 * @throws IllegalArgumentException if null structure, or null or empty potentialModifications, or potentialModifications contain  modifications other than ModifiedResidues.
 */
@Override public List<ModifiedCompound> parse(final Structure structure,final Set<ProteinModification> potentialModifications,final int modelnr){
  if (structure == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (potentialModifications == null || potentialModifications.isEmpty()) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  for (  ProteinModification mod : potentialModifications) {
    if (mod.getCategory() != ModificationCategory.CHEMICAL_MODIFICATION) {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  if (modelnr >= structure.nrModels())   return null;
  List<ModifiedCompound> ret=new ArrayList<ModifiedCompound>();
  List<Chain> chains=structure.getChains(modelnr);
  for (  Chain chain : chains) {
    List<Group> residues=chain.getSeqResGroups();
    int sizeRes=residues.size();
    for (int iRes=0; iRes < sizeRes; iRes++) {
      Group residue=residues.get(iRes);
      String pdbccId=residue.getPDBName();
      ProteinModification mod=ProteinModification.getByPdbccId(pdbccId);
      if (mod == null || !potentialModifications.contains(mod)) {
        continue;
      }
      ModificationCondition condition=mod.getCondition();
      Component comp=condition.getComponents().get(0);
      if ((comp.isNTerminal() && iRes != 0) || (comp.isCTerminal() && iRes != sizeRes - 1)) {
        continue;
      }
      ModifiedCompound modRes=ModifiedCompoundFactory.createModifiedResidue(mod,residue);
      ret.add(modRes);
    }
  }
  return ret;
}