Program: 91138
Project: 91138
Buggy source:
/** 
 * Creates a PROV Activity by querying the database using the given query and param. If the query uses the activity URI, param should be activity URI. And if the query uses the activity ID, param should be activity ID.
 */
protected int createActivity(Connection connection,String query,String param) throws QueryException, SQLException {
  PreparedStatement stmt=null;
  ResultSet resultSet=null;
  int activityID=-1;
  try {
    stmt=connection.prepareStatement(query);
    stmt.setString(1,param);
    resultSet=stmt.executeQuery();
    while (resultSet.next()) {
      activityID=resultSet.getInt("String_Node_Str");
      String activityUri=resultSet.getString("String_Node_Str");
      String activityType=resultSet.getString("String_Node_Str");
      String contextWorkflowUri=resultSet.getString("String_Node_Str");
      String contextServiceUri=resultSet.getString("String_Node_Str");
      String timestep=resultSet.getString("String_Node_Str");
      String contextWfNodeIdToken=resultSet.getString("String_Node_Str");
      Activity activity=pFactory.newActivity(getIdQName(QueryConstants.ACTIVITY_IDENTIFIER + activityID));
      if (infoDetailLevel != null && infoDetailLevel.equals(DetailEnumType.FINE)) {
        pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),activityUri,Name.QNAME_XSD_STRING));
        pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),activityType,Name.QNAME_XSD_STRING));
        if (contextWorkflowUri != null) {
          pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),contextWorkflowUri,Name.QNAME_XSD_STRING));
        }
        if (contextServiceUri != null) {
          pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),contextServiceUri,Name.QNAME_XSD_STRING));
        }
        if (timestep != null) {
          pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),timestep,Name.QNAME_XSD_STRING));
        }
        if (contextWfNodeIdToken != null) {
          pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),timestep,Name.QNAME_XSD_STRING));
        }
        addCustomAttributes(PROVSqlQuery.GET_EXE_ACTIVITY_ATTRIBUTES_BY_ID,"String_Node_Str" + activityID,activity,connection);
      }
      activities.put(activityID,activity);
    }
    l.debug("String_Node_Str");
  }
 catch (  SQLException e) {
    l.error("String_Node_Str");
    l.error(e.toString());
  }
 finally {
    if (stmt != null) {
      stmt.close();
    }
    if (resultSet != null) {
      resultSet.close();
    }
  }
  return activityID;
}

Fixed version (ground truth):
/** 
 * Creates a PROV Activity by querying the database using the given query and param. If the query uses the activity URI, param should be activity URI. And if the query uses the activity ID, param should be activity ID.
 */
protected int createActivity(Connection connection,String query,String param) throws QueryException, SQLException {
  PreparedStatement stmt=null;
  ResultSet resultSet=null;
  int activityID=-1;
  try {
    stmt=connection.prepareStatement(query);
    stmt.setString(1,param);
    resultSet=stmt.executeQuery();
    while (resultSet.next()) {
      activityID=resultSet.getInt("String_Node_Str");
      String activityUri=resultSet.getString("String_Node_Str");
      String activityType=resultSet.getString("String_Node_Str");
      String contextWorkflowUri=resultSet.getString("String_Node_Str");
      String contextServiceUri=resultSet.getString("String_Node_Str");
      String timestep=resultSet.getString("String_Node_Str");
      String contextWfNodeIdToken=resultSet.getString("String_Node_Str");
      Activity activity=pFactory.newActivity(getIdQName(QueryConstants.ACTIVITY_IDENTIFIER + activityID));
      if (infoDetailLevel != null && infoDetailLevel.equals(DetailEnumType.FINE)) {
        pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),activityUri,Name.QNAME_XSD_STRING));
        pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),activityType,Name.QNAME_XSD_STRING));
        if (contextWorkflowUri != null) {
          pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),contextWorkflowUri,Name.QNAME_XSD_STRING));
        }
        if (contextServiceUri != null) {
          pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),contextServiceUri,Name.QNAME_XSD_STRING));
        }
        if (timestep != null) {
          pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),timestep,Name.QNAME_XSD_STRING));
        }
        if (contextWfNodeIdToken != null) {
          pFactory.addAttribute(activity,pFactory.newOther(getKomaduAttQName("String_Node_Str"),contextWfNodeIdToken,Name.QNAME_XSD_STRING));
        }
        addCustomAttributes(PROVSqlQuery.GET_EXE_ACTIVITY_ATTRIBUTES_BY_ID,"String_Node_Str" + activityID,activity,connection);
      }
      activities.put(activityID,activity);
    }
    l.debug("String_Node_Str");
  }
 catch (  SQLException e) {
    l.error("String_Node_Str");
    l.error(e.toString());
  }
 finally {
    if (stmt != null) {
      stmt.close();
    }
    if (resultSet != null) {
      resultSet.close();
    }
  }
  return activityID;
}