Program: 7240
Project: 7240
Buggy source:
/** 
 * Compares this version of the project to a previous/new version to determine what are the updates and what was deleted
 * @param baselineProjectDB The previous baseline (build) for this Integrity CM Project
 * @param api The current Integrity API Session to obtain the author information
 * @param return The total number of changes found in the comparison
 * @throws SQLException 
 * @throws IOException 
 */
public int compareBaseline(File baselineProjectDB,APISession api) throws SQLException, IOException {
  changeCount=0;
  Connection baselineDB=DerbyUtils.createDBConnection(baselineProjectDB,dbName);
  Connection db=openProjectDB();
  Statement baselineSelect=null;
  Statement pjSelect=null;
  ResultSet baselineRS=null;
  ResultSet rs=null;
  try {
    baselineSelect=baselineDB.createStatement();
    Logger.debug("String_Node_Str" + DerbyUtils.BASELINE_SELECT);
    baselineRS=baselineSelect.executeQuery(DerbyUtils.BASELINE_SELECT);
    Hashtable<String,Hashtable<CM_PROJECT,Object>> baselinePJ=new Hashtable<String,Hashtable<CM_PROJECT,Object>>();
    while (baselineRS.next()) {
      Hashtable<CM_PROJECT,Object> rowHash=DerbyUtils.getRowData(baselineRS);
      Hashtable<CM_PROJECT,Object> memberInfo=new Hashtable<CM_PROJECT,Object>();
      memberInfo.put(CM_PROJECT.MEMBER_ID,(null == rowHash.get(CM_PROJECT.MEMBER_ID) ? "String_Node_Str" : rowHash.get(CM_PROJECT.MEMBER_ID).toString()));
      memberInfo.put(CM_PROJECT.TIMESTAMP,(null == rowHash.get(CM_PROJECT.TIMESTAMP) ? "String_Node_Str" : (Date)rowHash.get(CM_PROJECT.TIMESTAMP)));
      memberInfo.put(CM_PROJECT.DESCRIPTION,(null == rowHash.get(CM_PROJECT.DESCRIPTION) ? "String_Node_Str" : rowHash.get(CM_PROJECT.DESCRIPTION).toString()));
      memberInfo.put(CM_PROJECT.AUTHOR,(null == rowHash.get(CM_PROJECT.AUTHOR) ? "String_Node_Str" : rowHash.get(CM_PROJECT.AUTHOR).toString()));
      memberInfo.put(CM_PROJECT.CONFIG_PATH,(null == rowHash.get(CM_PROJECT.CONFIG_PATH) ? "String_Node_Str" : rowHash.get(CM_PROJECT.CONFIG_PATH).toString()));
      memberInfo.put(CM_PROJECT.REVISION,(null == rowHash.get(CM_PROJECT.REVISION) ? "String_Node_Str" : rowHash.get(CM_PROJECT.REVISION).toString()));
      memberInfo.put(CM_PROJECT.RELATIVE_FILE,(null == rowHash.get(CM_PROJECT.RELATIVE_FILE) ? "String_Node_Str" : rowHash.get(CM_PROJECT.RELATIVE_FILE).toString()));
      memberInfo.put(CM_PROJECT.CHECKSUM,(null == rowHash.get(CM_PROJECT.CHECKSUM) ? "String_Node_Str" : rowHash.get(CM_PROJECT.CHECKSUM).toString()));
      baselinePJ.put(rowHash.get(CM_PROJECT.NAME).toString(),memberInfo);
    }
    pjSelect=db.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    Logger.debug("String_Node_Str" + DerbyUtils.DELTA_SELECT);
    rs=pjSelect.executeQuery(DerbyUtils.DELTA_SELECT);
    for (int i=1; i <= DerbyUtils.getRowCount(rs); i++) {
      rs.absolute(i);
      Hashtable<CM_PROJECT,Object> rowHash=DerbyUtils.getRowData(rs);
      String memberName=rowHash.get(CM_PROJECT.NAME).toString();
      Logger.debug("String_Node_Str" + memberName);
      Hashtable<CM_PROJECT,Object> baselineMemberInfo=baselinePJ.get(memberName);
      if (null != baselineMemberInfo) {
        String oldRevision=baselineMemberInfo.get(CM_PROJECT.REVISION).toString();
        if (!rowHash.get(CM_PROJECT.REVISION).toString().equals(oldRevision)) {
          rs.updateString(CM_PROJECT.OLD_REVISION.toString(),oldRevision);
          if (!skipAuthorInfo) {
            rs.updateString(CM_PROJECT.AUTHOR.toString(),IntegrityCMMember.getAuthor(api,rowHash.get(CM_PROJECT.CONFIG_PATH).toString(),rowHash.get(CM_PROJECT.MEMBER_ID).toString(),rowHash.get(CM_PROJECT.REVISION).toString()));
          }
          rs.updateShort(CM_PROJECT.DELTA.toString(),(short)2);
          changeCount++;
        }
 else {
          if (null != baselineMemberInfo.get(CM_PROJECT.AUTHOR)) {
            rs.updateString(CM_PROJECT.AUTHOR.toString(),baselineMemberInfo.get(CM_PROJECT.AUTHOR).toString());
          }
          if (null != baselineMemberInfo.get(CM_PROJECT.CHECKSUM)) {
            rs.updateString(CM_PROJECT.CHECKSUM.toString(),baselineMemberInfo.get(CM_PROJECT.CHECKSUM).toString());
          }
          rs.updateShort(CM_PROJECT.DELTA.toString(),(short)0);
        }
        baselinePJ.remove(memberName);
      }
 else {
        if (!skipAuthorInfo) {
          rs.updateString(CM_PROJECT.AUTHOR.toString(),IntegrityCMMember.getAuthor(api,rowHash.get(CM_PROJECT.CONFIG_PATH).toString(),rowHash.get(CM_PROJECT.MEMBER_ID).toString(),rowHash.get(CM_PROJECT.REVISION).toString()));
        }
        rs.updateShort(CM_PROJECT.DELTA.toString(),(short)1);
        changeCount++;
      }
      rs.updateRow();
    }
    Enumeration<String> deletedMembers=baselinePJ.keys();
    while (deletedMembers.hasMoreElements()) {
      changeCount++;
      String memberName=deletedMembers.nextElement();
      Hashtable<CM_PROJECT,Object> memberInfo=baselinePJ.get(memberName);
      rs.moveToInsertRow();
      rs.updateShort(CM_PROJECT.TYPE.toString(),(short)0);
      rs.updateString(CM_PROJECT.NAME.toString(),memberName);
      rs.updateString(CM_PROJECT.MEMBER_ID.toString(),memberInfo.get(CM_PROJECT.MEMBER_ID).toString());
      if (memberInfo.get(CM_PROJECT.TIMESTAMP) instanceof java.util.Date) {
        Timestamp ts=new Timestamp(((Date)memberInfo.get(CM_PROJECT.TIMESTAMP)).getTime());
        rs.updateTimestamp(CM_PROJECT.TIMESTAMP.toString(),ts);
      }
      rs.updateString(CM_PROJECT.DESCRIPTION.toString(),memberInfo.get(CM_PROJECT.DESCRIPTION).toString());
      rs.updateString(CM_PROJECT.AUTHOR.toString(),memberInfo.get(CM_PROJECT.AUTHOR).toString());
      rs.updateString(CM_PROJECT.CONFIG_PATH.toString(),memberInfo.get(CM_PROJECT.CONFIG_PATH).toString());
      rs.updateString(CM_PROJECT.REVISION.toString(),memberInfo.get(CM_PROJECT.REVISION).toString());
      rs.updateString(CM_PROJECT.RELATIVE_FILE.toString(),memberInfo.get(CM_PROJECT.RELATIVE_FILE).toString());
      rs.updateShort(CM_PROJECT.DELTA.toString(),(short)3);
      rs.insertRow();
      rs.moveToCurrentRow();
    }
    db.commit();
  }
  finally {
    if (null != baselineRS) {
      baselineRS.close();
    }
    if (null != rs) {
      rs.close();
    }
    if (null != baselineSelect) {
      baselineSelect.close();
    }
    if (null != pjSelect) {
      pjSelect.close();
    }
    if (null != baselineDB) {
      baselineDB.close();
    }
    if (null != db) {
      db.close();
    }
    DerbyUtils.shutdownDB(baselineProjectDB,dbName);
  }
  return changeCount;
}

Fixed version (ground truth):
/** 
 * Compares this version of the project to a previous/new version to determine what are the updates and what was deleted
 * @param baselineProjectDB The previous baseline (build) for this Integrity CM Project
 * @param api The current Integrity API Session to obtain the author information
 * @param return The total number of changes found in the comparison
 * @throws SQLException 
 * @throws IOException 
 */
public int compareBaseline(File baselineProjectDB,APISession api) throws SQLException, IOException {
  changeCount=0;
  Connection baselineDB=DerbyUtils.createDBConnection(baselineProjectDB,dbName);
  Connection db=openProjectDB();
  Statement baselineSelect=null;
  Statement pjSelect=null;
  ResultSet baselineRS=null;
  ResultSet rs=null;
  try {
    baselineSelect=baselineDB.createStatement();
    Logger.debug("String_Node_Str" + DerbyUtils.BASELINE_SELECT);
    baselineRS=baselineSelect.executeQuery(DerbyUtils.BASELINE_SELECT);
    Hashtable<String,Hashtable<CM_PROJECT,Object>> baselinePJ=new Hashtable<String,Hashtable<CM_PROJECT,Object>>();
    while (baselineRS.next()) {
      Hashtable<CM_PROJECT,Object> rowHash=DerbyUtils.getRowData(baselineRS);
      Hashtable<CM_PROJECT,Object> memberInfo=new Hashtable<CM_PROJECT,Object>();
      memberInfo.put(CM_PROJECT.MEMBER_ID,(null == rowHash.get(CM_PROJECT.MEMBER_ID) ? "String_Node_Str" : rowHash.get(CM_PROJECT.MEMBER_ID).toString()));
      memberInfo.put(CM_PROJECT.TIMESTAMP,(null == rowHash.get(CM_PROJECT.TIMESTAMP) ? "String_Node_Str" : (Date)rowHash.get(CM_PROJECT.TIMESTAMP)));
      memberInfo.put(CM_PROJECT.DESCRIPTION,(null == rowHash.get(CM_PROJECT.DESCRIPTION) ? "String_Node_Str" : rowHash.get(CM_PROJECT.DESCRIPTION).toString()));
      memberInfo.put(CM_PROJECT.AUTHOR,(null == rowHash.get(CM_PROJECT.AUTHOR) ? "String_Node_Str" : rowHash.get(CM_PROJECT.AUTHOR).toString()));
      memberInfo.put(CM_PROJECT.CONFIG_PATH,(null == rowHash.get(CM_PROJECT.CONFIG_PATH) ? "String_Node_Str" : rowHash.get(CM_PROJECT.CONFIG_PATH).toString()));
      memberInfo.put(CM_PROJECT.REVISION,(null == rowHash.get(CM_PROJECT.REVISION) ? "String_Node_Str" : rowHash.get(CM_PROJECT.REVISION).toString()));
      memberInfo.put(CM_PROJECT.RELATIVE_FILE,(null == rowHash.get(CM_PROJECT.RELATIVE_FILE) ? "String_Node_Str" : rowHash.get(CM_PROJECT.RELATIVE_FILE).toString()));
      memberInfo.put(CM_PROJECT.CHECKSUM,(null == rowHash.get(CM_PROJECT.CHECKSUM) ? "String_Node_Str" : rowHash.get(CM_PROJECT.CHECKSUM).toString()));
      baselinePJ.put(rowHash.get(CM_PROJECT.NAME).toString(),memberInfo);
    }
    pjSelect=db.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    Logger.debug("String_Node_Str" + DerbyUtils.DELTA_SELECT);
    rs=pjSelect.executeQuery(DerbyUtils.DELTA_SELECT);
    for (int i=1; i <= DerbyUtils.getRowCount(rs); i++) {
      rs.absolute(i);
      Hashtable<CM_PROJECT,Object> rowHash=DerbyUtils.getRowData(rs);
      String memberName=rowHash.get(CM_PROJECT.NAME).toString();
      Logger.debug("String_Node_Str" + memberName);
      Hashtable<CM_PROJECT,Object> baselineMemberInfo=baselinePJ.get(memberName);
      if (null != baselineMemberInfo) {
        String oldRevision=baselineMemberInfo.get(CM_PROJECT.REVISION).toString();
        if (!rowHash.get(CM_PROJECT.REVISION).toString().equals(oldRevision)) {
          rs.updateString(CM_PROJECT.OLD_REVISION.toString(),oldRevision);
          if (!skipAuthorInfo) {
            rs.updateString(CM_PROJECT.AUTHOR.toString(),IntegrityCMMember.getAuthor(api,rowHash.get(CM_PROJECT.CONFIG_PATH).toString(),rowHash.get(CM_PROJECT.MEMBER_ID).toString(),rowHash.get(CM_PROJECT.REVISION).toString()));
          }
          rs.updateShort(CM_PROJECT.DELTA.toString(),(short)2);
          Logger.debug("String_Node_Str" + memberName + "String_Node_Str"+ rowHash.get(CM_PROJECT.REVISION).toString());
          changeCount++;
        }
 else {
          if (null != baselineMemberInfo.get(CM_PROJECT.AUTHOR)) {
            rs.updateString(CM_PROJECT.AUTHOR.toString(),baselineMemberInfo.get(CM_PROJECT.AUTHOR).toString());
          }
          if (null != baselineMemberInfo.get(CM_PROJECT.CHECKSUM)) {
            rs.updateString(CM_PROJECT.CHECKSUM.toString(),baselineMemberInfo.get(CM_PROJECT.CHECKSUM).toString());
          }
          rs.updateShort(CM_PROJECT.DELTA.toString(),(short)0);
        }
        baselinePJ.remove(memberName);
      }
 else {
        if (!skipAuthorInfo) {
          rs.updateString(CM_PROJECT.AUTHOR.toString(),IntegrityCMMember.getAuthor(api,rowHash.get(CM_PROJECT.CONFIG_PATH).toString(),rowHash.get(CM_PROJECT.MEMBER_ID).toString(),rowHash.get(CM_PROJECT.REVISION).toString()));
        }
        rs.updateShort(CM_PROJECT.DELTA.toString(),(short)1);
        Logger.debug("String_Node_Str" + memberName + "String_Node_Str"+ rowHash.get(CM_PROJECT.REVISION).toString());
        changeCount++;
      }
      rs.updateRow();
    }
    Enumeration<String> deletedMembers=baselinePJ.keys();
    while (deletedMembers.hasMoreElements()) {
      changeCount++;
      String memberName=deletedMembers.nextElement();
      Hashtable<CM_PROJECT,Object> memberInfo=baselinePJ.get(memberName);
      rs.moveToInsertRow();
      rs.updateShort(CM_PROJECT.TYPE.toString(),(short)0);
      rs.updateString(CM_PROJECT.NAME.toString(),memberName);
      rs.updateString(CM_PROJECT.MEMBER_ID.toString(),memberInfo.get(CM_PROJECT.MEMBER_ID).toString());
      if (memberInfo.get(CM_PROJECT.TIMESTAMP) instanceof java.util.Date) {
        Timestamp ts=new Timestamp(((Date)memberInfo.get(CM_PROJECT.TIMESTAMP)).getTime());
        rs.updateTimestamp(CM_PROJECT.TIMESTAMP.toString(),ts);
      }
      rs.updateString(CM_PROJECT.DESCRIPTION.toString(),memberInfo.get(CM_PROJECT.DESCRIPTION).toString());
      rs.updateString(CM_PROJECT.AUTHOR.toString(),memberInfo.get(CM_PROJECT.AUTHOR).toString());
      rs.updateString(CM_PROJECT.CONFIG_PATH.toString(),memberInfo.get(CM_PROJECT.CONFIG_PATH).toString());
      rs.updateString(CM_PROJECT.REVISION.toString(),memberInfo.get(CM_PROJECT.REVISION).toString());
      rs.updateString(CM_PROJECT.RELATIVE_FILE.toString(),memberInfo.get(CM_PROJECT.RELATIVE_FILE).toString());
      rs.updateShort(CM_PROJECT.DELTA.toString(),(short)3);
      rs.insertRow();
      rs.moveToCurrentRow();
      Logger.debug("String_Node_Str" + memberName + "String_Node_Str"+ memberInfo.get(CM_PROJECT.REVISION).toString());
    }
    db.commit();
  }
  finally {
    if (null != baselineRS) {
      baselineRS.close();
    }
    if (null != rs) {
      rs.close();
    }
    if (null != baselineSelect) {
      baselineSelect.close();
    }
    if (null != pjSelect) {
      pjSelect.close();
    }
    if (null != baselineDB) {
      baselineDB.close();
    }
    if (null != db) {
      db.close();
    }
    DerbyUtils.shutdownDB(baselineProjectDB,dbName);
  }
  return changeCount;
}