Program: 98227
Project: 98227
Buggy source:
/** 
 * @param queryTree This is a sub-query that does not contain OR operands.
 * @return QueryAdvise
 */
private QueryAdvice determineIndexToUseSub(QueryTreeNode queryTree){
  Map<ZooFieldDef,Long> minMap=new IdentityHashMap<ZooFieldDef,Long>();
  Map<ZooFieldDef,Long> maxMap=new IdentityHashMap<ZooFieldDef,Long>();
  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 (ZooFieldDef d2 : minMap.keySet()) {
long min2=minMap.get(d2);
long max2=maxMap.get(d2);
if ((max2 - min2) < (qa.getMax() - qa.getMin())) {
qa.setIndex(d2);
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.
 * @return QueryAdvise
 */
private QueryAdvice determineIndexToUseSub(QueryTreeNode queryTree){
  Map<ZooFieldDef,Long> minMap=new IdentityHashMap<ZooFieldDef,Long>();
  Map<ZooFieldDef,Long> maxMap=new IdentityHashMap<ZooFieldDef,Long>();
  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;
}