Program: 64083
Project: 64083
Buggy source:
/** 
 * INTERNAL: Select all rows from a abstract table descriptor. This is accomplished by selecting for all of the concrete classes and then merging the rows.
 * @return vector containing database rows.
 * @exception DatabaseException - an error has occurred on the database.
 */
protected Vector selectAllRowUsingDefaultMultipleTableSubclassRead(ReadAllQuery query) throws DatabaseException, QueryException {
  List<AbstractRecord> classIndicators=((ExpressionQueryMechanism)query.getQueryMechanism()).selectAllRowsFromTable();
  List<Class> classes=new ArrayList<Class>();
  Set<Class> uniqueClasses=new HashSet<Class>();
  for (  AbstractRecord row : classIndicators) {
    Class concreteClass=classFromRow(row,query.getSession());
    if (!uniqueClasses.contains(concreteClass)) {
      uniqueClasses.add(concreteClass);
      classes.add(concreteClass);
    }
  }
  Vector rows=new Vector();
  HashMap joinedMappingIndexes=null;
  if (query.hasJoining()) {
    joinedMappingIndexes=new HashMap();
  }
  ClassDescriptor rootDescriptor=query.getDescriptor();
  for (  Class concreteClass : classes) {
    if (!uniqueClasses.contains(concreteClass)) {
      continue;
    }
    query.getSession().logMessage("String_Node_Str" + concreteClass);
    Set<Class> subclasses=new HashSet<Class>();
    uniqueClasses.remove(concreteClass);
    subclasses.add(concreteClass);
    ClassDescriptor concreteDescriptor=getDescriptor(concreteClass);
    if (concreteDescriptor == null) {
      throw QueryException.noDescriptorForClassFromInheritancePolicy(query,concreteClass);
    }
    InheritancePolicy concretePolicy=concreteDescriptor.getInheritancePolicy();
    ClassDescriptor parentDescriptor=concretePolicy.getParentDescriptor();
    while ((parentDescriptor != null) && (parentDescriptor != rootDescriptor) && !parentDescriptor.getInheritancePolicy().hasMultipleTableChild()&& parentDescriptor.getInheritancePolicy().shouldReadSubclasses()) {
      concreteDescriptor=parentDescriptor;
      concreteClass=concreteDescriptor.getJavaClass();
      uniqueClasses.remove(concreteClass);
      subclasses.add(concreteClass);
      concretePolicy=concreteDescriptor.getInheritancePolicy();
      parentDescriptor=concretePolicy.getParentDescriptor();
      query.getSession().logMessage("String_Node_Str" + concreteClass);
    }
    if (concretePolicy.hasChildren() && !concretePolicy.hasMultipleTableChild()) {
      removeChildren(concreteDescriptor,uniqueClasses,subclasses);
    }
    ReadAllQuery concreteQuery=(ReadAllQuery)query.clone();
    concreteQuery.setReferenceClass(concreteClass);
    concreteQuery.setDescriptor(concreteDescriptor);
    Vector concreteRows=((ExpressionQueryMechanism)concreteQuery.getQueryMechanism()).selectAllRowsFromConcreteTable();
    rows=Helper.concatenateVectors(rows,concreteRows);
    if (joinedMappingIndexes != null) {
      for (      Map.Entry entry : concreteQuery.getJoinedAttributeManager().getJoinedMappingIndexes_().entrySet()) {
        HashMap mappingIndexes=(HashMap)joinedMappingIndexes.get(entry.getKey());
        if (mappingIndexes == null) {
          mappingIndexes=new HashMap(classes.size());
          joinedMappingIndexes.put(entry.getKey(),mappingIndexes);
        }
        for (        Class subclass : subclasses) {
          mappingIndexes.put(subclass,entry.getValue());
        }
      }
    }
  }
  if (joinedMappingIndexes != null) {
    query.getJoinedAttributeManager().setJoinedMappingIndexes_(joinedMappingIndexes);
  }
  return rows;
}

Fixed version (ground truth):
/** 
 * INTERNAL: Select all rows from a abstract table descriptor. This is accomplished by selecting for all of the concrete classes and then merging the rows.
 * @return vector containing database rows.
 * @exception DatabaseException - an error has occurred on the database.
 */
protected Vector selectAllRowUsingDefaultMultipleTableSubclassRead(ObjectLevelReadQuery query) throws DatabaseException, QueryException {
  List<AbstractRecord> classIndicators=((ExpressionQueryMechanism)query.getQueryMechanism()).selectAllRowsFromTable();
  List<Class> classes=new ArrayList<Class>();
  Set<Class> uniqueClasses=new HashSet<Class>();
  for (  AbstractRecord row : classIndicators) {
    Class concreteClass=classFromRow(row,query.getSession());
    if (!uniqueClasses.contains(concreteClass)) {
      uniqueClasses.add(concreteClass);
      classes.add(concreteClass);
    }
  }
  Vector rows=new Vector();
  HashMap joinedMappingIndexes=null;
  if (query.hasJoining()) {
    joinedMappingIndexes=new HashMap();
  }
  ClassDescriptor rootDescriptor=query.getDescriptor();
  for (  Class concreteClass : classes) {
    if (!uniqueClasses.contains(concreteClass)) {
      continue;
    }
    query.getSession().logMessage("String_Node_Str" + concreteClass);
    Set<Class> subclasses=new HashSet<Class>();
    uniqueClasses.remove(concreteClass);
    subclasses.add(concreteClass);
    ClassDescriptor concreteDescriptor=getDescriptor(concreteClass);
    if (concreteDescriptor == null) {
      throw QueryException.noDescriptorForClassFromInheritancePolicy(query,concreteClass);
    }
    InheritancePolicy concretePolicy=concreteDescriptor.getInheritancePolicy();
    ClassDescriptor parentDescriptor=concretePolicy.getParentDescriptor();
    while ((parentDescriptor != null) && (parentDescriptor != rootDescriptor) && !parentDescriptor.getInheritancePolicy().hasMultipleTableChild()&& parentDescriptor.getInheritancePolicy().shouldReadSubclasses()) {
      concreteDescriptor=parentDescriptor;
      concreteClass=concreteDescriptor.getJavaClass();
      uniqueClasses.remove(concreteClass);
      subclasses.add(concreteClass);
      concretePolicy=concreteDescriptor.getInheritancePolicy();
      parentDescriptor=concretePolicy.getParentDescriptor();
      query.getSession().logMessage("String_Node_Str" + concreteClass);
    }
    if (concretePolicy.hasChildren() && !concretePolicy.hasMultipleTableChild()) {
      removeChildren(concreteDescriptor,uniqueClasses,subclasses);
    }
    ObjectLevelReadQuery concreteQuery=(ObjectLevelReadQuery)query.clone();
    concreteQuery.setReferenceClass(concreteClass);
    concreteQuery.setDescriptor(concreteDescriptor);
    Vector concreteRows=((ExpressionQueryMechanism)concreteQuery.getQueryMechanism()).selectAllRowsFromConcreteTable();
    rows=Helper.concatenateVectors(rows,concreteRows);
    if (joinedMappingIndexes != null) {
      for (      Map.Entry entry : concreteQuery.getJoinedAttributeManager().getJoinedMappingIndexes_().entrySet()) {
        HashMap mappingIndexes=(HashMap)joinedMappingIndexes.get(entry.getKey());
        if (mappingIndexes == null) {
          mappingIndexes=new HashMap(classes.size());
          joinedMappingIndexes.put(entry.getKey(),mappingIndexes);
        }
        for (        Class subclass : subclasses) {
          mappingIndexes.put(subclass,entry.getValue());
        }
      }
    }
  }
  if (joinedMappingIndexes != null) {
    query.getJoinedAttributeManager().setJoinedMappingIndexes_(joinedMappingIndexes);
  }
  return rows;
}