Program: 16683
Project: 16683
Buggy source:
/** 
 * Handler for ATOM Record Format <pre> ATOM      1  N   ASP A  15     110.964  24.941  59.191  1.00 83.44           N COLUMNS        DATA TYPE       FIELD         DEFINITION --------------------------------------------------------------------------------- 1 -  6        Record name     "ATOM  " 7 - 11        Integer         serial        Atom serial number. 13 - 16        Atom            name          Atom name. 17             Character       altLoc        Alternate location indicator. 18 - 20        Residue name    resName       Residue name. 22             Character       chainID       Chain identifier. 23 - 26        Integer         resSeq        Residue sequence number. 27             AChar           iCode         Code for insertion of residues. 31 - 38        Real(8.3)       x             Orthogonal coordinates for X in Angstroms. 39 - 46        Real(8.3)       y             Orthogonal coordinates for Y in Angstroms. 47 - 54        Real(8.3)       z             Orthogonal coordinates for Z in Angstroms. 55 - 60        Real(6.2)       occupancy     Occupancy. 61 - 66        Real(6.2)       tempFactor    Temperature factor. 73 - 76        LString(4)      segID         Segment identifier, left-justified. 77 - 78        LString(2)      element       Element symbol, right-justified. 79 - 80        LString(2)      charge        Charge on the atom. </pre>
 */
private void pdb_ATOM_Handler(String line){
  boolean startOfNewChain=false;
  String chain_id=line.substring(21,22);
  if (current_chain == null) {
    current_chain=new ChainImpl();
    current_chain.setChainID(chain_id);
    startOfNewChain=true;
    current_model.add(current_chain);
  }
  if (!chain_id.equals(current_chain.getChainID())) {
    startOfNewChain=true;
    current_chain.addGroup(current_group);
    Chain testchain;
    testchain=isKnownChain(current_chain.getChainID(),current_model);
    if (testchain != null && testchain.getChainID().equals(chain_id)) {
    }
 else {
      testchain=isKnownChain(chain_id,current_model);
    }
    if (testchain == null) {
      current_chain=new ChainImpl();
      current_chain.setChainID(chain_id);
    }
 else {
      current_chain=testchain;
    }
    if (!current_model.contains(current_chain))     current_model.add(current_chain);
  }
  String recordName=line.substring(0,6).trim();
  String groupCode3=line.substring(17,20);
  String resNum=line.substring(22,26).trim();
  Character iCode=line.substring(26,27).charAt(0);
  if (iCode == ' ')   iCode=null;
  ResidueNumber residueNumber=new ResidueNumber(chain_id,Integer.valueOf(resNum),iCode);
  Character aminoCode1=null;
  if (recordName.equals("String_Node_Str")) {
    aminoCode1=StructureTools.get1LetterCode(groupCode3);
  }
 else {
    aminoCode1=StructureTools.get1LetterCode(groupCode3);
    if (aminoCode1 != null)     if (aminoCode1.equals(StructureTools.UNKNOWN_GROUP_LABEL))     aminoCode1=null;
  }
  if (current_group == null) {
    current_group=getNewGroup(recordName,aminoCode1,groupCode3);
    current_group.setPDBName(groupCode3);
    current_group.setResidueNumber(residueNumber);
    addTohetGroupsDecider(current_group);
  }
  if (startOfNewChain) {
    current_group=getNewGroup(recordName,aminoCode1,groupCode3);
    current_group.setPDBName(groupCode3);
    current_group.setResidueNumber(residueNumber);
    addTohetGroupsDecider(current_group);
  }
  Character altLoc=new Character(line.substring(16,17).charAt(0));
  Group altGroup=null;
  if (!residueNumber.equals(current_group.getResidueNumber())) {
    current_chain.addGroup(current_group);
    current_group.trimToSize();
    current_group=getNewGroup(recordName,aminoCode1,groupCode3);
    current_group.setPDBName(groupCode3);
    current_group.setResidueNumber(residueNumber);
    addTohetGroupsDecider(current_group);
  }
 else {
    if (!altLoc.equals(' ')) {
      logger.debug("String_Node_Str" + current_group + "String_Node_Str"+ altGroup);
      altGroup=getCorrectAltLocGroup(altLoc,recordName,aminoCode1,groupCode3);
      if (altGroup.getChain() == null) {
        altGroup.setChain(current_chain);
      }
    }
  }
  if (params.isHeaderOnly())   return;
  atomCount++;
  if (atomCount == my_ATOM_CA_THRESHOLD) {
    logger.warn("String_Node_Str" + my_ATOM_CA_THRESHOLD + "String_Node_Str");
    seqResChains.clear();
    switchCAOnly();
  }
  if (atomCount == load_max_atoms) {
    logger.warn("String_Node_Str" + load_max_atoms + "String_Node_Str");
    logger.warn("String_Node_Str" + line);
    return;
  }
  if (atomCount > load_max_atoms) {
    return;
  }
  String fullname=line.substring(12,16);
  if (parseCAonly) {
    if (!fullname.equals("String_Node_Str")) {
      atomCount--;
      return;
    }
  }
  if (params.getAcceptedAtomNames() != null) {
    boolean found=false;
    for (    String ok : params.getAcceptedAtomNames()) {
      if (ok.equals(fullname.trim())) {
        found=true;
        break;
      }
    }
    if (!found) {
      atomCount--;
      return;
    }
  }
  int pdbnumber=Integer.parseInt(line.substring(6,11).trim());
  AtomImpl atom=new AtomImpl();
  atom.setPDBserial(pdbnumber);
  atom.setAltLoc(altLoc);
  atom.setName(fullname.trim());
  double x=Double.parseDouble(line.substring(30,38).trim());
  double y=Double.parseDouble(line.substring(38,46).trim());
  double z=Double.parseDouble(line.substring(46,54).trim());
  double[] coords=new double[3];
  coords[0]=x;
  coords[1]=y;
  coords[2]=z;
  atom.setCoords(coords);
  double occu=1.0;
  if (line.length() > 59) {
    try {
      occu=Double.parseDouble(line.substring(54,60).trim());
    }
 catch (    NumberFormatException e) {
    }
  }
  double tempf=0.0;
  if (line.length() > 65) {
    try {
      tempf=Double.parseDouble(line.substring(60,66).trim());
    }
 catch (    NumberFormatException e) {
    }
  }
  atom.setOccupancy(occu);
  atom.setTempFactor(tempf);
  Element element=Element.R;
  if (line.length() > 77) {
    try {
      element=Element.valueOfIgnoreCase(line.substring(76,78).trim());
    }
 catch (    IllegalArgumentException e) {
    }
  }
 else {
    String elementSymbol=null;
    if (fullname.trim().length() == 4) {
      elementSymbol=fullname.substring(0,1);
    }
 else     if (fullname.trim().length() > 1) {
      elementSymbol=fullname.substring(0,2).trim();
    }
 else {
      elementSymbol="String_Node_Str";
    }
    try {
      element=Element.valueOfIgnoreCase(elementSymbol);
    }
 catch (    IllegalArgumentException e) {
    }
  }
  atom.setElement(element);
  if (altGroup != null) {
    altGroup.addAtom(atom);
    altGroup=null;
  }
 else {
    current_group.addAtom(atom);
  }
  if (!current_group.hasAtom(atom.getName())) {
    current_group.addAtom(atom);
  }
}

Fixed version (ground truth):
/** 
 * Handler for ATOM Record Format <pre> ATOM      1  N   ASP A  15     110.964  24.941  59.191  1.00 83.44           N COLUMNS        DATA TYPE       FIELD         DEFINITION --------------------------------------------------------------------------------- 1 -  6        Record name     "ATOM  " 7 - 11        Integer         serial        Atom serial number. 13 - 16        Atom            name          Atom name. 17             Character       altLoc        Alternate location indicator. 18 - 20        Residue name    resName       Residue name. 22             Character       chainID       Chain identifier. 23 - 26        Integer         resSeq        Residue sequence number. 27             AChar           iCode         Code for insertion of residues. 31 - 38        Real(8.3)       x             Orthogonal coordinates for X in Angstroms. 39 - 46        Real(8.3)       y             Orthogonal coordinates for Y in Angstroms. 47 - 54        Real(8.3)       z             Orthogonal coordinates for Z in Angstroms. 55 - 60        Real(6.2)       occupancy     Occupancy. 61 - 66        Real(6.2)       tempFactor    Temperature factor. 73 - 76        LString(4)      segID         Segment identifier, left-justified. 77 - 78        LString(2)      element       Element symbol, right-justified. 79 - 80        LString(2)      charge        Charge on the atom. </pre>
 */
private void pdb_ATOM_Handler(String line){
  boolean startOfNewChain=false;
  String chain_id=line.substring(21,22);
  if (current_chain == null) {
    current_chain=new ChainImpl();
    current_chain.setChainID(chain_id);
    startOfNewChain=true;
    current_model.add(current_chain);
  }
  if (!chain_id.equals(current_chain.getChainID())) {
    startOfNewChain=true;
    current_chain.addGroup(current_group);
    Chain testchain;
    testchain=isKnownChain(current_chain.getChainID(),current_model);
    if (testchain != null && testchain.getChainID().equals(chain_id)) {
    }
 else {
      testchain=isKnownChain(chain_id,current_model);
    }
    if (testchain == null) {
      current_chain=new ChainImpl();
      current_chain.setChainID(chain_id);
    }
 else {
      current_chain=testchain;
    }
    if (!current_model.contains(current_chain))     current_model.add(current_chain);
  }
  String recordName=line.substring(0,6).trim();
  String groupCode3=line.substring(17,20).trim();
  String resNum=line.substring(22,26).trim();
  Character iCode=line.substring(26,27).charAt(0);
  if (iCode == ' ')   iCode=null;
  ResidueNumber residueNumber=new ResidueNumber(chain_id,Integer.valueOf(resNum),iCode);
  Character aminoCode1=null;
  if (recordName.equals("String_Node_Str")) {
    aminoCode1=StructureTools.get1LetterCode(groupCode3);
  }
 else {
    aminoCode1=StructureTools.get1LetterCode(groupCode3);
    if (aminoCode1 != null)     if (aminoCode1.equals(StructureTools.UNKNOWN_GROUP_LABEL))     aminoCode1=null;
  }
  if (current_group == null) {
    current_group=getNewGroup(recordName,aminoCode1,groupCode3);
    current_group.setPDBName(groupCode3);
    current_group.setResidueNumber(residueNumber);
    addTohetGroupsDecider(current_group);
  }
  if (startOfNewChain) {
    current_group=getNewGroup(recordName,aminoCode1,groupCode3);
    current_group.setPDBName(groupCode3);
    current_group.setResidueNumber(residueNumber);
    addTohetGroupsDecider(current_group);
  }
  Character altLoc=new Character(line.substring(16,17).charAt(0));
  Group altGroup=null;
  if (!residueNumber.equals(current_group.getResidueNumber())) {
    current_chain.addGroup(current_group);
    current_group.trimToSize();
    current_group=getNewGroup(recordName,aminoCode1,groupCode3);
    current_group.setPDBName(groupCode3);
    current_group.setResidueNumber(residueNumber);
    addTohetGroupsDecider(current_group);
  }
 else {
    if (!altLoc.equals(' ')) {
      logger.debug("String_Node_Str" + current_group + "String_Node_Str"+ altGroup);
      altGroup=getCorrectAltLocGroup(altLoc,recordName,aminoCode1,groupCode3);
      if (altGroup.getChain() == null) {
        altGroup.setChain(current_chain);
      }
    }
  }
  if (params.isHeaderOnly())   return;
  atomCount++;
  if (atomCount == my_ATOM_CA_THRESHOLD) {
    logger.warn("String_Node_Str" + my_ATOM_CA_THRESHOLD + "String_Node_Str");
    seqResChains.clear();
    switchCAOnly();
  }
  if (atomCount == load_max_atoms) {
    logger.warn("String_Node_Str" + load_max_atoms + "String_Node_Str");
    logger.warn("String_Node_Str" + line);
    return;
  }
  if (atomCount > load_max_atoms) {
    return;
  }
  String fullname=line.substring(12,16);
  if (parseCAonly) {
    if (!fullname.equals("String_Node_Str")) {
      atomCount--;
      return;
    }
  }
  if (params.getAcceptedAtomNames() != null) {
    boolean found=false;
    for (    String ok : params.getAcceptedAtomNames()) {
      if (ok.equals(fullname.trim())) {
        found=true;
        break;
      }
    }
    if (!found) {
      atomCount--;
      return;
    }
  }
  int pdbnumber=Integer.parseInt(line.substring(6,11).trim());
  AtomImpl atom=new AtomImpl();
  atom.setPDBserial(pdbnumber);
  atom.setAltLoc(altLoc);
  atom.setName(fullname.trim());
  double x=Double.parseDouble(line.substring(30,38).trim());
  double y=Double.parseDouble(line.substring(38,46).trim());
  double z=Double.parseDouble(line.substring(46,54).trim());
  double[] coords=new double[3];
  coords[0]=x;
  coords[1]=y;
  coords[2]=z;
  atom.setCoords(coords);
  double occu=1.0;
  if (line.length() > 59) {
    try {
      occu=Double.parseDouble(line.substring(54,60).trim());
    }
 catch (    NumberFormatException e) {
    }
  }
  double tempf=0.0;
  if (line.length() > 65) {
    try {
      tempf=Double.parseDouble(line.substring(60,66).trim());
    }
 catch (    NumberFormatException e) {
    }
  }
  atom.setOccupancy(occu);
  atom.setTempFactor(tempf);
  Element element=Element.R;
  if (line.length() > 77) {
    try {
      element=Element.valueOfIgnoreCase(line.substring(76,78).trim());
    }
 catch (    IllegalArgumentException e) {
    }
  }
 else {
    String elementSymbol=null;
    if (fullname.trim().length() == 4) {
      elementSymbol=fullname.substring(0,1);
    }
 else     if (fullname.trim().length() > 1) {
      elementSymbol=fullname.substring(0,2).trim();
    }
 else {
      elementSymbol="String_Node_Str";
    }
    try {
      element=Element.valueOfIgnoreCase(elementSymbol);
    }
 catch (    IllegalArgumentException e) {
    }
  }
  atom.setElement(element);
  if (altGroup != null) {
    altGroup.addAtom(atom);
    altGroup=null;
  }
 else {
    current_group.addAtom(atom);
  }
  if (!current_group.hasAtom(atom.getName())) {
    current_group.addAtom(atom);
  }
}