Program: 38713
Project: 38713
Buggy source:
@Override public Set<T> findAllByForeignKey(String foreignKey,Set<Long> ids) throws IOException {
  Map<Long,Set<T>> foreignKeyCache=cachedByForeignKey.get(foreignKey);
  Set<T> foundSet=new HashSet<T>();
  Set<Long> notCachedIds=new HashSet<Long>();
  if (foreignKeyCache != null && useCache) {
    for (    Long id : ids) {
      Set<T> results=foreignKeyCache.get(id);
      if (results != null) {
        foundSet.addAll(results);
      }
 else {
        notCachedIds.add(id);
      }
    }
  }
 else {
    notCachedIds=ids;
    if (useCache) {
      foreignKeyCache=new HashMap<Long,Set<T>>();
      cachedByForeignKey.put(foreignKey,foreignKeyCache);
    }
  }
  if (!notCachedIds.isEmpty()) {
    StringBuilder statementString=new StringBuilder();
    statementString.append("String_Node_Str");
    statementString.append(tableName);
    statementString.append("String_Node_Str" + foreignKey + "String_Node_Str");
    Iterator<Long> iter=notCachedIds.iterator();
    while (iter.hasNext()) {
      Long obj=iter.next();
      statementString.append(obj.toString());
      if (iter.hasNext()) {
        statementString.append("String_Node_Str");
      }
    }
    statementString.append("String_Node_Str");
    PreparedStatement stmt=conn.getPreparedStatement(statementString.toString());
    ResultSet rs=null;
    try {
      rs=stmt.executeQuery();
      while (rs.next()) {
        T inst=instanceFromResultSet(rs);
        foundSet.add(inst);
        if (useCache) {
          cachedById.put(inst.getId(),inst);
        }
      }
    }
 catch (    SQLException e) {
      throw new IOException(e);
    }
  }
  return foundSet;
}

Fixed version (ground truth):
@Override public Set<T> findAllByForeignKey(String foreignKey,Set<Long> ids) throws IOException {
  Map<Long,Set<T>> foreignKeyCache=cachedByForeignKey.get(foreignKey);
  Set<T> foundSet=new HashSet<T>();
  Set<Long> notCachedIds=new HashSet<Long>();
  if (foreignKeyCache != null && useCache) {
    for (    Long id : ids) {
      Set<T> results=foreignKeyCache.get(id);
      if (results != null) {
        foundSet.addAll(results);
      }
 else {
        notCachedIds.add(id);
      }
    }
  }
 else {
    notCachedIds=ids;
    if (useCache) {
      foreignKeyCache=new HashMap<Long,Set<T>>();
      cachedByForeignKey.put(foreignKey,foreignKeyCache);
    }
  }
  if (!notCachedIds.isEmpty()) {
    StringBuilder statementString=new StringBuilder();
    statementString.append("String_Node_Str");
    statementString.append(tableName);
    statementString.append("String_Node_Str" + foreignKey + "String_Node_Str");
    Iterator<Long> iter=notCachedIds.iterator();
    while (iter.hasNext()) {
      Long obj=iter.next();
      statementString.append(obj.toString());
      if (iter.hasNext()) {
        statementString.append("String_Node_Str");
      }
    }
    statementString.append("String_Node_Str");
    PreparedStatement stmt=conn.getPreparedStatement(statementString.toString());
    ResultSet rs=null;
    try {
      rs=stmt.executeQuery();
      while (rs.next()) {
        T inst=instanceFromResultSet(rs);
        inst.setCreated(true);
        foundSet.add(inst);
        if (useCache) {
          cachedById.put(inst.getId(),inst);
        }
      }
    }
 catch (    SQLException e) {
      throw new IOException(e);
    }
  }
  return foundSet;
}