Program: 98195
Project: 98195
Buggy source:
/** 
 * @param queryTree This is a sub-query that does not contain OR operands.
 * @param maxMap2 
 * @param minMap2 
 * @return QueryAdvise
 */
private QueryAdvice determineIndexToUseSub(QueryTreeNode queryTree,IdentityHashMap<ZooFieldDef,Long> minMap,IdentityHashMap<ZooFieldDef,Long> maxMap){
  QueryTreeIterator iter=queryTree.termIterator();
  while (iter.hasNext()) {
    QueryTerm term=iter.next();
    ZooFieldDef f=term.getFieldDef();
    if (!f.isIndexed()) {
      continue;
    }
    Long minVal=minMap.get(f);
    if (minVal == null) {
      minMap.put(f,f.getMinValue());
      maxMap.put(f,f.getMaxValue());
    }
    Long value;
    if (term.getValue() instanceof Number) {
      value=((Number)term.getValue()).longValue();
    }
 else     if (term.getValue() instanceof String) {
      value=BitTools.toSortableLong((String)term.getValue());
    }
 else     if (term.getValue() instanceof Boolean) {
      continue;
    }
 else {
      throw new IllegalArgumentException("String_Node_Str" + term.getValue().getClass());
    }
switch (term.getOp()) {
case EQ:
{
        minMap.put(f,value);
        maxMap.put(f,value);
        break;
      }
case L:
    if (value < maxMap.get(f)) {
      maxMap.put(f,value - 1);
    }
  break;
case LE:
if (value < maxMap.get(f)) {
  maxMap.put(f,value);
}
break;
case A:
if (value > minMap.get(f)) {
minMap.put(f,value + 1);
}
break;
case AE:
if (value > minMap.get(f)) {
minMap.put(f,value);
}
break;
case NE:
break;
default :
throw new IllegalArgumentException("String_Node_Str" + term.getOp());
}
}
if (minMap.isEmpty()) {
return new QueryAdvice(queryTree);
}
ZooFieldDef def=minMap.keySet().iterator().next();
QueryAdvice qa=new QueryAdvice(queryTree);
qa.setIndex(def);
qa.setMin(minMap.get(def));
qa.setMax(maxMap.get(def));
if (minMap.size() == 1) {
qa.setIndex(minMap.keySet().iterator().next());
return qa;
}
for (Map.Entry<ZooFieldDef,Long> me2 : minMap.entrySet()) {
long min2=me2.getValue();
long max2=maxMap.get(me2.getKey());
if ((max2 - min2) < (qa.getMax() - qa.getMin())) {
qa.setIndex(me2.getKey());
qa.setMin(min2);
qa.setMax(max2);
}
}
if (qa.getIndex().isString()) {
qa.setMin(BitTools.getMinPosInPage(qa.getMin()));
qa.setMax(BitTools.getMaxPosInPage(qa.getMax()));
}
return qa;
}

Fixed version (ground truth):
/** 
 * @param queryTree This is a sub-query that does not contain OR operands.
 * @param maxMap2 
 * @param minMap2 
 * @return QueryAdvise
 */
private QueryAdvice determineIndexToUseSub(QueryTreeNode queryTree,IdentityHashMap<ZooFieldDef,Long> minMap,IdentityHashMap<ZooFieldDef,Long> maxMap){
  QueryTreeIterator iter=queryTree.termIterator();
  while (iter.hasNext()) {
    QueryTerm term=iter.next();
    ZooFieldDef f=term.getFieldDef();
    if (!f.isIndexed()) {
      continue;
    }
    Long minVal=minMap.get(f);
    if (minVal == null) {
      minMap.put(f,f.getMinValue());
      maxMap.put(f,f.getMaxValue());
    }
    Long value;
    if (term.getValue() == QueryParser.NULL) {
      continue;
    }
 else     if (term.getValue() instanceof Number) {
      value=((Number)term.getValue()).longValue();
    }
 else     if (term.getValue() instanceof String) {
      value=BitTools.toSortableLong((String)term.getValue());
    }
 else     if (term.getValue() instanceof Boolean) {
      continue;
    }
 else {
      throw new IllegalArgumentException("String_Node_Str" + term.getValue().getClass());
    }
switch (term.getOp()) {
case EQ:
{
        minMap.put(f,value);
        maxMap.put(f,value);
        break;
      }
case L:
    if (value < maxMap.get(f)) {
      maxMap.put(f,value - 1);
    }
  break;
case LE:
if (value < maxMap.get(f)) {
  maxMap.put(f,value);
}
break;
case A:
if (value > minMap.get(f)) {
minMap.put(f,value + 1);
}
break;
case AE:
if (value > minMap.get(f)) {
minMap.put(f,value);
}
break;
case NE:
break;
default :
throw new IllegalArgumentException("String_Node_Str" + term.getOp());
}
}
if (minMap.isEmpty()) {
return new QueryAdvice(queryTree);
}
ZooFieldDef def=minMap.keySet().iterator().next();
QueryAdvice qa=new QueryAdvice(queryTree);
qa.setIndex(def);
qa.setMin(minMap.get(def));
qa.setMax(maxMap.get(def));
if (minMap.size() == 1) {
qa.setIndex(minMap.keySet().iterator().next());
return qa;
}
for (Map.Entry<ZooFieldDef,Long> me2 : minMap.entrySet()) {
long min2=me2.getValue();
long max2=maxMap.get(me2.getKey());
if ((max2 - min2) < (qa.getMax() - qa.getMin())) {
qa.setIndex(me2.getKey());
qa.setMin(min2);
qa.setMax(max2);
}
}
if (qa.getIndex().isString()) {
qa.setMin(BitTools.getMinPosInPage(qa.getMin()));
qa.setMax(BitTools.getMaxPosInPage(qa.getMax()));
}
return qa;
}