Program: 16480
Project: 16480
Buggy source:
/** 
 * Function to pass data from Biojava structure  to another generic output type.Loops through the data  structure and calls all the set functions.
 * @param dataTransferInterface the generic interface that implements all the set methods.
 */
public MmtfStructureWriter(Structure data,StructureAdapterInterface dataTransferInterface){
  this.mmtfDecoderInterface=dataTransferInterface;
  MmtfUtils.fixMicroheterogenity(structure);
  MmtfSummaryDataBean mmtfSummaryDataBean=MmtfUtils.getStructureInfo(structure);
  Map<String,Integer> chainIdToIndexMap=mmtfSummaryDataBean.getChainIdToIndexMap();
  List<Atom> allAtoms=mmtfSummaryDataBean.getAllAtoms();
  int numBonds=mmtfSummaryDataBean.getNumBonds();
  List<Chain> allChains=mmtfSummaryDataBean.getAllChains();
  mmtfDecoderInterface.initStructure(numBonds,allAtoms.size(),MmtfUtils.getNumGroups(structure),allChains.size(),structure.nrModels(),structure.getPDBCode());
  MmtfUtils.calculateDsspSecondaryStructure(structure);
  PDBHeader pdbHeader=structure.getPDBHeader();
  PDBCrystallographicInfo xtalInfo=pdbHeader.getCrystallographicInfo();
  String releaseDate=null;
  mmtfDecoderInterface.setHeaderInfo(pdbHeader.getRfree(),1.0f,pdbHeader.getResolution(),pdbHeader.getTitle(),MmtfUtils.dateToIsoString(pdbHeader.getDepDate()),releaseDate,MmtfUtils.techniquesToStringArray(pdbHeader.getExperimentalTechniques()));
  mmtfDecoderInterface.setXtalInfo(MmtfUtils.getSpaceGroupAsString(xtalInfo.getSpaceGroup()),MmtfUtils.getUnitCellAsArray(xtalInfo));
  storeBioassemblyInformation(chainIdToIndexMap,pdbHeader.getBioAssemblies());
  storeEntityInformation(allChains,structure.getEntityInfos());
  for (int modelIndex=0; modelIndex < structure.nrModels(); modelIndex++) {
    List<Chain> modelChains=structure.getChains(modelIndex);
    mmtfDecoderInterface.setModelInfo(modelIndex,modelChains.size());
    for (int chainInModelIndex=0; chainInModelIndex < modelChains.size(); chainInModelIndex++) {
      Chain chain=modelChains.get(chainInModelIndex);
      List<Group> groups=chain.getAtomGroups();
      List<Group> sequenceGroups=chain.getSeqResGroups();
      mmtfDecoderInterface.setChainInfo(chain.getChainID(),chain.getInternalChainID(),groups.size());
      for (int groupInChainIndex=0; groupInChainIndex < groups.size(); groupInChainIndex++) {
        Group group=groups.get(groupInChainIndex);
        List<Atom> atomsInGroup=MmtfUtils.getAtomsForGroup(group);
        ChemComp chemComp=group.getChemComp();
        Character insCode=group.getResidueNumber().getInsCode();
        if (insCode == null) {
          insCode=MmtfBean.UNAVAILABLE_CHAR_VALUE;
        }
        char singleLetterCode='X';
        if (chemComp.getOne_letter_code().charAt(0) != '?') {
          singleLetterCode=chemComp.getOne_letter_code().charAt(0);
        }
        mmtfDecoderInterface.setGroupInfo(group.getPDBName(),group.getResidueNumber().getSeqNum(),insCode.charValue(),chemComp.getType(),atomsInGroup.size(),MmtfUtils.getNumBondsInGroup(atomsInGroup),singleLetterCode,sequenceGroups.indexOf(group),MmtfUtils.getSecStructType(group));
        for (        Atom atom : atomsInGroup) {
          char altLoc=MmtfBean.UNAVAILABLE_CHAR_VALUE;
          if (atom.getAltLoc() != null) {
            altLoc=atom.getAltLoc().charValue();
          }
          mmtfDecoderInterface.setAtomInfo(atom.getName(),atom.getPDBserial(),altLoc,(float)atom.getX(),(float)atom.getY(),(float)atom.getZ(),atom.getOccupancy(),atom.getTempFactor(),atom.getElement().toString(),atom.getCharge());
          addBonds(atom,atomsInGroup,allAtoms);
        }
      }
    }
  }
  mmtfDecoderInterface.finalizeStructure();
}

Fixed version (ground truth):
/** 
 * Function to pass data from Biojava structure  to another generic output type.Loops through the data  structure and calls all the set functions.
 * @param dataTransferInterface the generic interface that implements all the set methods.
 */
public MmtfStructureWriter(Structure data,StructureAdapterInterface dataTransferInterface){
  this.mmtfDecoderInterface=dataTransferInterface;
  this.structure=data;
  MmtfUtils.fixMicroheterogenity(structure);
  MmtfSummaryDataBean mmtfSummaryDataBean=MmtfUtils.getStructureInfo(structure);
  Map<String,Integer> chainIdToIndexMap=mmtfSummaryDataBean.getChainIdToIndexMap();
  List<Atom> allAtoms=mmtfSummaryDataBean.getAllAtoms();
  int numBonds=mmtfSummaryDataBean.getNumBonds();
  List<Chain> allChains=mmtfSummaryDataBean.getAllChains();
  mmtfDecoderInterface.initStructure(numBonds,allAtoms.size(),MmtfUtils.getNumGroups(structure),allChains.size(),structure.nrModels(),structure.getPDBCode());
  MmtfUtils.calculateDsspSecondaryStructure(structure);
  PDBHeader pdbHeader=structure.getPDBHeader();
  PDBCrystallographicInfo xtalInfo=pdbHeader.getCrystallographicInfo();
  String releaseDate=null;
  mmtfDecoderInterface.setHeaderInfo(pdbHeader.getRfree(),1.0f,pdbHeader.getResolution(),pdbHeader.getTitle(),MmtfUtils.dateToIsoString(pdbHeader.getDepDate()),releaseDate,MmtfUtils.techniquesToStringArray(pdbHeader.getExperimentalTechniques()));
  mmtfDecoderInterface.setXtalInfo(MmtfUtils.getSpaceGroupAsString(xtalInfo.getSpaceGroup()),MmtfUtils.getUnitCellAsArray(xtalInfo));
  storeBioassemblyInformation(chainIdToIndexMap,pdbHeader.getBioAssemblies());
  storeEntityInformation(allChains,structure.getEntityInfos());
  for (int modelIndex=0; modelIndex < structure.nrModels(); modelIndex++) {
    List<Chain> modelChains=structure.getChains(modelIndex);
    mmtfDecoderInterface.setModelInfo(modelIndex,modelChains.size());
    for (int chainInModelIndex=0; chainInModelIndex < modelChains.size(); chainInModelIndex++) {
      Chain chain=modelChains.get(chainInModelIndex);
      List<Group> groups=chain.getAtomGroups();
      List<Group> sequenceGroups=chain.getSeqResGroups();
      mmtfDecoderInterface.setChainInfo(chain.getChainID(),chain.getInternalChainID(),groups.size());
      for (int groupInChainIndex=0; groupInChainIndex < groups.size(); groupInChainIndex++) {
        Group group=groups.get(groupInChainIndex);
        List<Atom> atomsInGroup=MmtfUtils.getAtomsForGroup(group);
        ChemComp chemComp=group.getChemComp();
        Character insCode=group.getResidueNumber().getInsCode();
        if (insCode == null) {
          insCode=MmtfBean.UNAVAILABLE_CHAR_VALUE;
        }
        char singleLetterCode='X';
        if (chemComp.getOne_letter_code().charAt(0) != '?') {
          singleLetterCode=chemComp.getOne_letter_code().charAt(0);
        }
        mmtfDecoderInterface.setGroupInfo(group.getPDBName(),group.getResidueNumber().getSeqNum(),insCode.charValue(),chemComp.getType(),atomsInGroup.size(),MmtfUtils.getNumBondsInGroup(atomsInGroup),singleLetterCode,sequenceGroups.indexOf(group),MmtfUtils.getSecStructType(group));
        for (        Atom atom : atomsInGroup) {
          char altLoc=MmtfBean.UNAVAILABLE_CHAR_VALUE;
          if (atom.getAltLoc() != null) {
            altLoc=atom.getAltLoc().charValue();
          }
          mmtfDecoderInterface.setAtomInfo(atom.getName(),atom.getPDBserial(),altLoc,(float)atom.getX(),(float)atom.getY(),(float)atom.getZ(),atom.getOccupancy(),atom.getTempFactor(),atom.getElement().toString(),atom.getCharge());
          addBonds(atom,atomsInGroup,allAtoms);
        }
      }
    }
  }
  mmtfDecoderInterface.finalizeStructure();
}