Program: 97979
Project: 97979
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();
    if (!term.isRhsFixed() || term.isLhsFunction()) {
      if (term.isLhsFunction()) {
        determineIndexToUseSubForQueryFunctions(minMap,maxMap,term.getLhsFunction());
      }
      continue;
    }
    ZooFieldDef f=term.getLhsFieldDef();
    if (f == null || !f.isIndexed()) {
      continue;
    }
    Long minVal=minMap.get(f);
    if (minVal == null) {
      minMap.put(f,f.getMinValue());
      maxMap.put(f,f.getMaxValue());
    }
    Object termVal=term.getValue(null);
    Long value;
switch (f.getJdoType()) {
case PRIMITIVE:
switch (f.getPrimitiveType()) {
case BOOLEAN:
        continue;
case DOUBLE:
      value=BitTools.toSortableLong((termVal instanceof Double ? (double)termVal : (double)(float)termVal));
    break;
case FLOAT:
  value=BitTools.toSortableLong((termVal instanceof Float ? (float)termVal : (float)(double)termVal));
break;
case CHAR:
value=(long)((Character)termVal).charValue();
case BYTE:
case INT:
case LONG:
case SHORT:
value=((Number)termVal).longValue();
break;
default :
throw new IllegalArgumentException("String_Node_Str" + f.getPrimitiveType());
}
break;
case STRING:
value=BitTools.toSortableLong(termVal == QueryTerm.NULL ? null : (String)termVal);
break;
case REFERENCE:
value=(termVal == QueryTerm.NULL ? BitTools.NULL : ((ZooPC)termVal).jdoZooGetOid());
break;
case DATE:
value=(termVal == QueryTerm.NULL ? 0 : ((Date)termVal).getTime());
break;
default :
throw new IllegalArgumentException("String_Node_Str" + f.getJdoType());
}
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:
case STR_matches:
case STR_contains_NON_JDO:
case STR_endsWith:
break;
case STR_startsWith:
setKeysForStringStartsWith((String)term.getValue(null),f,minMap,maxMap);
break;
default :
throw new IllegalArgumentException("String_Node_Str" + term.getOp());
}
}
return createQueryAdvice(minMap,maxMap,queryTree);
}

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();
    if (!term.isRhsFixed() || term.isLhsFunction()) {
      if (term.isLhsFunction()) {
        determineIndexToUseSubForQueryFunctions(minMap,maxMap,term.getLhsFunction());
      }
      continue;
    }
    ZooFieldDef f=term.getLhsFieldDef();
    if (f == null || !f.isIndexed()) {
      continue;
    }
    Long minVal=minMap.get(f);
    if (minVal == null) {
      minMap.put(f,f.getMinValue());
      maxMap.put(f,f.getMaxValue());
    }
    Object termVal=term.getValue(null);
    Long value;
switch (f.getJdoType()) {
case PRIMITIVE:
switch (f.getPrimitiveType()) {
case BOOLEAN:
        continue;
case DOUBLE:
      value=BitTools.toSortableLong((termVal instanceof Double ? (double)termVal : (double)(float)termVal));
    break;
case FLOAT:
  value=BitTools.toSortableLong((termVal instanceof Float ? (float)termVal : (float)(double)termVal));
break;
case CHAR:
value=(long)((Character)termVal).charValue();
break;
case BYTE:
case INT:
case LONG:
case SHORT:
value=((Number)termVal).longValue();
break;
default :
throw new IllegalArgumentException("String_Node_Str" + f.getPrimitiveType());
}
break;
case STRING:
value=BitTools.toSortableLong(termVal == QueryTerm.NULL ? null : (String)termVal);
break;
case REFERENCE:
value=(termVal == QueryTerm.NULL ? BitTools.NULL : ((ZooPC)termVal).jdoZooGetOid());
break;
case DATE:
value=(termVal == QueryTerm.NULL ? 0 : ((Date)termVal).getTime());
break;
default :
throw new IllegalArgumentException("String_Node_Str" + f.getJdoType());
}
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:
case STR_matches:
case STR_contains_NON_JDO:
case STR_endsWith:
break;
case STR_startsWith:
setKeysForStringStartsWith((String)term.getValue(null),f,minMap,maxMap);
break;
default :
throw new IllegalArgumentException("String_Node_Str" + term.getOp());
}
}
return createQueryAdvice(minMap,maxMap,queryTree);
}