Program: 89697
Project: 89697
Buggy source:
/** 
 * Create a harvest definition in Database. The harvest definition object should not have its ID set unless we are in the middle of migrating.
 * @param harvestDefinition A new harvest definition to store inthe database.
 * @return The harvestId for the just created harvest definition.
 * @see HarvestDefinitionDAO#create(HarvestDefinition)
 */
public synchronized Long create(HarvestDefinition harvestDefinition){
  Connection connection=HarvestDBConnection.get();
  PreparedStatement s=null;
  try {
    Long id=harvestDefinition.getOid();
    if (id == null) {
      id=generateNextID(connection);
    }
    connection.setAutoCommit(false);
    s=connection.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str");
    s.setLong(1,id);
    DBUtils.setName(s,2,harvestDefinition,Constants.MAX_NAME_SIZE);
    DBUtils.setComments(s,3,harvestDefinition,Constants.MAX_COMMENT_SIZE);
    s.setLong(4,harvestDefinition.getNumEvents());
    Date submissiondate=new Date();
    s.setTimestamp(5,new Timestamp(submissiondate.getTime()));
    s.setBoolean(6,harvestDefinition.getActive());
    final int edition=1;
    s.setLong(7,edition);
    s.executeUpdate();
    s.close();
    if (harvestDefinition instanceof FullHarvest) {
      FullHarvest fh=(FullHarvest)harvestDefinition;
      s=connection.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str");
      s.setLong(1,id);
      s.setLong(2,fh.getMaxCountObjects());
      s.setLong(3,fh.getMaxBytes());
      s.setLong(4,fh.getMaxJobRunningTime());
      if (fh.getPreviousHarvestDefinition() != null) {
        s.setLong(5,fh.getPreviousHarvestDefinition().getOid());
      }
 else {
        s.setNull(5,Types.BIGINT);
      }
      s.executeUpdate();
    }
 else     if (harvestDefinition instanceof PartialHarvest) {
      PartialHarvest ph=(PartialHarvest)harvestDefinition;
      long scheduleId=DBUtils.selectLongValue(connection,"String_Node_Str",ph.getSchedule().getName());
      s=connection.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
      s.setLong(1,id);
      s.setLong(2,scheduleId);
      DBUtils.setDateMaybeNull(s,3,ph.getNextDate());
      s.executeUpdate();
      createHarvestConfigsEntries(connection,ph,id);
    }
 else {
      String message="String_Node_Str" + harvestDefinition + "String_Node_Str"+ harvestDefinition.getClass();
      log.warn(message);
      throw new ArgumentNotValid(message);
    }
    connection.commit();
    harvestDefinition.setSubmissionDate(submissiondate);
    harvestDefinition.setEdition(edition);
    harvestDefinition.setOid(id);
    return id;
  }
 catch (  SQLException e) {
    String message="String_Node_Str" + harvestDefinition + "String_Node_Str"+ "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e);
    log.warn(message,e);
    throw new IOFailure(message,e);
  }
 finally {
    DBUtils.rollbackIfNeeded(connection,"String_Node_Str",harvestDefinition);
    HarvestDBConnection.release(connection);
  }
}

Fixed version (ground truth):
/** 
 * Create a harvest definition in Database. The harvest definition object should not have its ID set unless we are in the middle of migrating.
 * @param harvestDefinition A new harvest definition to store inthe database.
 * @return The harvestId for the just created harvest definition.
 * @see HarvestDefinitionDAO#create(HarvestDefinition)
 */
@Override public synchronized Long create(HarvestDefinition harvestDefinition){
  Connection connection=HarvestDBConnection.get();
  PreparedStatement s=null;
  try {
    Long id=harvestDefinition.getOid();
    if (id == null) {
      id=generateNextID(connection);
    }
    connection.setAutoCommit(false);
    s=connection.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str");
    s.setLong(1,id);
    DBUtils.setName(s,2,harvestDefinition,Constants.MAX_NAME_SIZE);
    DBUtils.setComments(s,3,harvestDefinition,Constants.MAX_COMMENT_SIZE);
    s.setLong(4,harvestDefinition.getNumEvents());
    Date submissiondate=new Date();
    s.setTimestamp(5,new Timestamp(submissiondate.getTime()));
    s.setBoolean(6,harvestDefinition.getActive());
    final int edition=1;
    s.setLong(7,edition);
    s.executeUpdate();
    s.close();
    if (harvestDefinition instanceof FullHarvest) {
      FullHarvest fh=(FullHarvest)harvestDefinition;
      s=connection.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str");
      s.setLong(1,id);
      s.setLong(2,fh.getMaxCountObjects());
      s.setLong(3,fh.getMaxBytes());
      s.setLong(4,fh.getMaxJobRunningTime());
      if (fh.getPreviousHarvestDefinition() != null) {
        s.setLong(5,fh.getPreviousHarvestDefinition().getOid());
      }
 else {
        s.setNull(5,Types.BIGINT);
      }
      s.executeUpdate();
    }
 else     if (harvestDefinition instanceof PartialHarvest) {
      PartialHarvest ph=(PartialHarvest)harvestDefinition;
      long scheduleId=DBUtils.selectLongValue(connection,"String_Node_Str",ph.getSchedule().getName());
      s=connection.prepareStatement("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
      s.setLong(1,id);
      s.setLong(2,scheduleId);
      DBUtils.setDateMaybeNull(s,3,ph.getNextDate());
      s.executeUpdate();
      createHarvestConfigsEntries(connection,ph,id);
    }
 else {
      String message="String_Node_Str" + harvestDefinition + "String_Node_Str"+ harvestDefinition.getClass();
      log.warn(message);
      throw new ArgumentNotValid(message);
    }
    connection.commit();
    harvestDefinition.setSubmissionDate(submissiondate);
    harvestDefinition.setEdition(edition);
    harvestDefinition.setOid(id);
    return id;
  }
 catch (  SQLException e) {
    String message="String_Node_Str" + harvestDefinition + "String_Node_Str"+ "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e);
    log.warn(message,e);
    throw new IOFailure(message,e);
  }
 finally {
    DBUtils.rollbackIfNeeded(connection,"String_Node_Str",harvestDefinition);
    HarvestDBConnection.release(connection);
  }
}