Program: 101405
Project: 101405
Buggy source:
/** 
 * Projects the query into the concept space.
 * @param query
 * @return Returns concept vector results exist, otherwise null 
 * @throws IOException
 * @throws SQLException
 */
public IConceptVector getConceptVector(String query) throws IOException, SQLException {
  if (caching && esaCache.containsKey(query)) {
    return esaCache.get(query);
  }
  String strTerm;
  int numTerms=0;
  ResultSet rs;
  int doc;
  double score;
  int vint;
  double vdouble;
  double tf;
  double vsum;
  int plen;
  this.clean();
  values.clear();
  query=Utils.removeDiacriticalMarks(query);
  TokenStream ts=analyzer.tokenStream("String_Node_Str",new StringReader(query));
  ts.reset();
  while (ts.incrementToken()) {
    TermAttribute t=ts.getAttribute(TermAttribute.class);
    strTerm=t.term();
    if (strTerm.equals("String_Node_Str") || strTerm.equals("String_Node_Str")) {
      continue;
    }
    termList.add(strTerm);
    numTerms++;
  }
  ts.end();
  ts.close();
  ByteArrayInputStream bais;
  DataInputStream dis;
  if (!loadToMemory) {
    db.executeUpdate("String_Node_Str");
    db.executeUpdate("String_Node_Str");
    PreparedStatement psTTerms=db.getConnection().prepareStatement("String_Node_Str");
    for (    String t : termList) {
      psTTerms.setBytes(1,t.getBytes("String_Node_Str"));
      psTTerms.addBatch();
    }
    psTTerms.executeBatch();
    psTTerms.close();
    ResultSet res;
    esaNdx.clear();
    esaIdf.clear();
    res=db.executeSelect("String_Node_Str" + lang + "String_Node_Str");
    while (res.next()) {
      esaNdx.put(new String(res.getBytes("String_Node_Str"),"String_Node_Str"),res.getBytes("String_Node_Str"));
    }
    res.close();
    res=db.executeSelect("String_Node_Str" + lang + "String_Node_Str");
    while (res.next()) {
      esaIdf.put(new String(res.getBytes("String_Node_Str"),"String_Node_Str"),res.getFloat("String_Node_Str"));
    }
    res.close();
  }
  for (  String t : termList) {
    if (!idfMap.containsKey(t)) {
      Float idf=esaIdf.get(t);
      if (idf != null) {
        idfMap.put(t,idf);
      }
    }
    if (freqMap.containsKey(t)) {
      vint=freqMap.get(t);
      freqMap.put(t,vint + 1);
    }
 else {
      freqMap.put(t,1);
    }
  }
  if (numTerms == 0) {
    return null;
  }
  vsum=0;
  for (  String tk : idfMap.keySet()) {
    tf=1.0 + Math.log(freqMap.get(tk));
    vdouble=(idfMap.get(tk) * tf);
    tfidfMap.put(tk,vdouble);
    vsum+=vdouble * vdouble;
  }
  vsum=Math.sqrt(vsum);
  for (  String tk : idfMap.keySet()) {
    vdouble=tfidfMap.get(tk);
    tfidfMap.put(tk,vdouble / vsum);
  }
  score=0;
  for (  String tk : termList) {
    byte[] rss=esaNdx.get(tk);
    score=0;
    if (rss != null) {
      bais=new ByteArrayInputStream(rss);
      dis=new DataInputStream(bais);
      plen=dis.readInt();
      for (int k=0; k < plen; k++) {
        doc=dis.readInt();
        score=dis.readFloat();
        float scoreF=(float)(score * tfidfMap.get(tk));
        values.adjustOrPutValue(doc,scoreF,scoreF);
      }
      dis.close();
      bais.close();
    }
  }
  float[] valuesF=values.getValues();
  ids=values.keys();
  HeapSort.heapSort(valuesF,ids);
  IConceptVector newCv=new TroveConceptVector(ids.length);
  for (int i=ids.length - 1; i >= 0 && valuesF[i] > 0; i--) {
    newCv.set(ids[i],valuesF[i] / numTerms);
  }
  if (caching) {
    esaCache.put(query,newCv);
  }
  return newCv;
}

Fixed version (ground truth):
/** 
 * Projects the query into the concept space.
 * @param query
 * @return Returns concept vector results exist, otherwise null 
 * @throws IOException
 * @throws SQLException
 */
public IConceptVector getConceptVector(String query) throws IOException, SQLException {
  if (caching && esaCache.containsKey(query)) {
    return esaCache.get(query);
  }
  String strTerm;
  int numTerms=0;
  ResultSet rs;
  int doc;
  double score;
  int vint;
  double vdouble;
  double tf;
  double vsum;
  int plen;
  this.clean();
  values.clear();
  query=Utils.removeDiacriticalMarks(query);
  TokenStream ts=analyzer.tokenStream("String_Node_Str",new StringReader(query));
  ts.reset();
  while (ts.incrementToken()) {
    TermAttribute t=ts.getAttribute(TermAttribute.class);
    strTerm=t.term();
    if (strTerm.equals("String_Node_Str") || strTerm.equals("String_Node_Str")) {
      continue;
    }
    termList.add(strTerm);
    numTerms++;
  }
  ts.end();
  ts.close();
  ByteArrayInputStream bais;
  DataInputStream dis;
  if (!loadToMemory) {
    db.executeUpdate("String_Node_Str");
    db.executeUpdate("String_Node_Str");
    PreparedStatement psTTerms=db.getConnection().prepareStatement("String_Node_Str");
    for (    String t : termList) {
      psTTerms.setBytes(1,t.getBytes("String_Node_Str"));
      psTTerms.addBatch();
    }
    psTTerms.executeBatch();
    psTTerms.close();
    ResultSet res;
    esaNdx.clear();
    esaIdf.clear();
    res=db.executeSelect("String_Node_Str" + lang + "String_Node_Str");
    while (res.next()) {
      esaNdx.put(new String(res.getBytes("String_Node_Str"),"String_Node_Str"),res.getBytes("String_Node_Str"));
    }
    res.close();
    res=db.executeSelect("String_Node_Str" + lang + "String_Node_Str");
    while (res.next()) {
      esaIdf.put(new String(res.getBytes("String_Node_Str"),"String_Node_Str"),res.getFloat("String_Node_Str"));
    }
    res.close();
  }
  for (  String t : termList) {
    if (!idfMap.containsKey(t)) {
      Float idf=esaIdf.get(t);
      if (idf != null) {
        idfMap.put(t,idf);
      }
    }
    if (freqMap.containsKey(t)) {
      vint=freqMap.get(t);
      freqMap.put(t,vint + 1);
    }
 else {
      freqMap.put(t,1);
    }
  }
  if (numTerms == 0) {
    return null;
  }
  vsum=0;
  for (  String tk : idfMap.keySet()) {
    tf=1.0 + Math.log(freqMap.get(tk));
    vdouble=(idfMap.get(tk) * tf);
    tfidfMap.put(tk,vdouble);
    vsum+=vdouble * vdouble;
  }
  vsum=Math.sqrt(vsum);
  for (  String tk : idfMap.keySet()) {
    vdouble=tfidfMap.get(tk);
    tfidfMap.put(tk,vdouble / vsum);
  }
  score=0;
  for (  String tk : termList) {
    byte[] rss=esaNdx.get(tk);
    score=0;
    if (rss != null) {
      bais=new ByteArrayInputStream(rss);
      dis=new DataInputStream(bais);
      plen=dis.readInt();
      for (int k=0; k < plen; k++) {
        doc=dis.readInt();
        score=dis.readFloat();
        float scoreF=(float)(score * tfidfMap.get(tk));
        values.adjustOrPutValue(doc,scoreF,scoreF);
      }
      dis.close();
      bais.close();
    }
  }
  float[] valuesF=values.getValues();
  ids=values.keys();
  HeapSort.heapSort(valuesF,ids);
  IConceptVector newCv=new TroveConceptVector(ids.length);
  for (int i=ids.length - 1; i >= 0 && valuesF[i] > 0; i--) {
    newCv.set(ids[i],valuesF[i] / numTerms);
  }
  if (caching) {
    esaCache.put(query,newCv);
  }
  if (newCv.count() > 0)   return newCv;
 else   return null;
}