Program: 65816
Project: 65816
Buggy source:
public java.util.List<Type> define(Schema schema,boolean includeAllTypes,boolean processImports){
  java.util.List<Type> returnList=new ArrayList<Type>();
  setReturnAllTypes(includeAllTypes);
  setProcessImports(processImports);
  processSchema(schema);
  returnList.addAll(getGeneratedTypes().values());
  returnList.addAll(anonymousTypes);
  if (!this.isImportProcessor()) {
    java.util.List descriptorsToAdd=new ArrayList(returnList);
    Iterator<Type> iter=descriptorsToAdd.iterator();
    while (iter.hasNext()) {
      SDOType nextSDOType=(SDOType)iter.next();
      if (!nextSDOType.isFinalized()) {
        throw SDOException.typeReferencedButNotDefined(nextSDOType.getURI(),nextSDOType.getName());
      }
      Iterator<Property> propertiesIter=nextSDOType.getProperties().iterator();
      while (propertiesIter.hasNext()) {
        SDOProperty prop=(SDOProperty)propertiesIter.next();
        if (prop.getType().isDataType() && prop.isContainment()) {
          prop.setContainment(false);
        }
      }
    }
    Iterator<Property> propertiesIter=getGeneratedGlobalElements().values().iterator();
    while (propertiesIter.hasNext()) {
      SDOProperty nextSDOProperty=(SDOProperty)propertiesIter.next();
      if (!nextSDOProperty.isFinalized()) {
        throw SDOException.referencedPropertyNotFound(nextSDOProperty.getUri(),nextSDOProperty.getName());
      }
    }
    propertiesIter=getGeneratedGlobalAttributes().values().iterator();
    while (propertiesIter.hasNext()) {
      SDOProperty nextSDOProperty=(SDOProperty)propertiesIter.next();
      if (!nextSDOProperty.isFinalized()) {
        throw SDOException.referencedPropertyNotFound(nextSDOProperty.getUri(),nextSDOProperty.getName());
      }
    }
    iter=getGeneratedTypes().values().iterator();
    while (iter.hasNext()) {
      SDOType nextSDOType=(SDOType)iter.next();
      ((SDOTypeHelper)aHelperContext.getTypeHelper()).addType(nextSDOType);
    }
    Iterator anonymousIterator=getAnonymousTypes().iterator();
    while (anonymousIterator.hasNext()) {
      SDOType nextSDOType=(SDOType)anonymousIterator.next();
      ((SDOTypeHelper)aHelperContext.getTypeHelper()).getAnonymousTypes().add(nextSDOType);
    }
    for (int i=0; i < descriptorsToAdd.size(); i++) {
      SDOType nextSDOType=(SDOType)descriptorsToAdd.get(i);
      if (!nextSDOType.isDataType() && nextSDOType.getBaseTypes().size() == 0 && nextSDOType.getSubTypes().size() > 0) {
        nextSDOType.setupInheritance(null);
      }
 else       if (!nextSDOType.isDataType() && nextSDOType.getBaseTypes().size() > 0 && !getGeneratedTypes().values().contains(nextSDOType.getBaseTypes().get(0))) {
        SDOType baseType=(SDOType)nextSDOType.getBaseTypes().get(0);
        while (baseType != null) {
          descriptorsToAdd.add(baseType);
          if (baseType.getBaseTypes().size() == 0) {
            baseType.setupInheritance(null);
            baseType=null;
          }
 else {
            baseType=(SDOType)baseType.getBaseTypes().get(0);
          }
        }
      }
    }
    ((SDOXMLHelper)aHelperContext.getXMLHelper()).addDescriptors(descriptorsToAdd);
    Iterator<QName> qNameIter=getGeneratedGlobalElements().keySet().iterator();
    while (qNameIter.hasNext()) {
      QName nextQName=qNameIter.next();
      SDOProperty nextSDOProperty=(SDOProperty)getGeneratedGlobalElements().get(nextQName);
      ((SDOXSDHelper)aHelperContext.getXSDHelper()).addGlobalProperty(nextQName,nextSDOProperty,true);
    }
    qNameIter=getGeneratedGlobalAttributes().keySet().iterator();
    while (qNameIter.hasNext()) {
      QName nextQName=qNameIter.next();
      SDOProperty nextSDOProperty=(SDOProperty)getGeneratedGlobalAttributes().get(nextQName);
      ((SDOXSDHelper)aHelperContext.getXSDHelper()).addGlobalProperty(nextQName,nextSDOProperty,false);
    }
    Iterator<java.util.List<GlobalRef>> globalRefsIter=getGlobalRefs().values().iterator();
    while (globalRefsIter.hasNext()) {
      java.util.List<GlobalRef> nextList=globalRefsIter.next();
      if (nextList.size() > 0) {
        GlobalRef ref=nextList.get(0);
        throw SDOException.referencedPropertyNotFound(((SDOProperty)ref.getProperty()).getUri(),ref.getProperty().getName());
      }
    }
  }
  return returnList;
}

Fixed version (ground truth):
public java.util.List<Type> define(Schema schema,boolean includeAllTypes,boolean processImports){
  java.util.List<Type> returnList=new ArrayList<Type>();
  setReturnAllTypes(includeAllTypes);
  setProcessImports(processImports);
  processSchema(schema);
  returnList.addAll(getGeneratedTypes().values());
  returnList.addAll(anonymousTypes);
  if (!this.isImportProcessor()) {
    java.util.List descriptorsToAdd=new ArrayList(returnList);
    Iterator<Type> iter=descriptorsToAdd.iterator();
    while (iter.hasNext()) {
      SDOType nextSDOType=(SDOType)iter.next();
      if (!nextSDOType.isFinalized()) {
        throw SDOException.typeReferencedButNotDefined(nextSDOType.getURI(),nextSDOType.getName());
      }
      Iterator<Property> propertiesIter=nextSDOType.getProperties().iterator();
      while (propertiesIter.hasNext()) {
        SDOProperty prop=(SDOProperty)propertiesIter.next();
        if (prop.getType().isDataType() && prop.isContainment()) {
          prop.setContainment(false);
        }
      }
    }
    Iterator<Property> propertiesIter=getGeneratedGlobalElements().values().iterator();
    while (propertiesIter.hasNext()) {
      SDOProperty nextSDOProperty=(SDOProperty)propertiesIter.next();
      if (!nextSDOProperty.isFinalized()) {
        throw SDOException.referencedPropertyNotFound(nextSDOProperty.getUri(),nextSDOProperty.getName());
      }
    }
    propertiesIter=getGeneratedGlobalAttributes().values().iterator();
    while (propertiesIter.hasNext()) {
      SDOProperty nextSDOProperty=(SDOProperty)propertiesIter.next();
      if (!nextSDOProperty.isFinalized()) {
        throw SDOException.referencedPropertyNotFound(nextSDOProperty.getUri(),nextSDOProperty.getName());
      }
    }
    iter=getGeneratedTypes().values().iterator();
    while (iter.hasNext()) {
      SDOType nextSDOType=(SDOType)iter.next();
      ((SDOTypeHelper)aHelperContext.getTypeHelper()).addType(nextSDOType);
    }
    Iterator anonymousIterator=getAnonymousTypes().iterator();
    while (anonymousIterator.hasNext()) {
      SDOType nextSDOType=(SDOType)anonymousIterator.next();
      ((SDOTypeHelper)aHelperContext.getTypeHelper()).getAnonymousTypes().add(nextSDOType);
    }
    for (int i=0; i < descriptorsToAdd.size(); i++) {
      SDOType nextSDOType=(SDOType)descriptorsToAdd.get(i);
      if (!nextSDOType.isDataType() && !nextSDOType.isSubType() && nextSDOType.isBaseType()) {
        nextSDOType.setupInheritance(null);
      }
 else       if (!nextSDOType.isDataType() && nextSDOType.isSubType() && !getGeneratedTypes().values().contains(nextSDOType.getBaseTypes().get(0))) {
        SDOType baseType=(SDOType)nextSDOType.getBaseTypes().get(0);
        while (baseType != null) {
          descriptorsToAdd.add(baseType);
          if (baseType.getBaseTypes().size() == 0) {
            baseType.setupInheritance(null);
            baseType=null;
          }
 else {
            baseType=(SDOType)baseType.getBaseTypes().get(0);
          }
        }
      }
    }
    ((SDOXMLHelper)aHelperContext.getXMLHelper()).addDescriptors(descriptorsToAdd);
    Iterator<QName> qNameIter=getGeneratedGlobalElements().keySet().iterator();
    while (qNameIter.hasNext()) {
      QName nextQName=qNameIter.next();
      SDOProperty nextSDOProperty=(SDOProperty)getGeneratedGlobalElements().get(nextQName);
      ((SDOXSDHelper)aHelperContext.getXSDHelper()).addGlobalProperty(nextQName,nextSDOProperty,true);
    }
    qNameIter=getGeneratedGlobalAttributes().keySet().iterator();
    while (qNameIter.hasNext()) {
      QName nextQName=qNameIter.next();
      SDOProperty nextSDOProperty=(SDOProperty)getGeneratedGlobalAttributes().get(nextQName);
      ((SDOXSDHelper)aHelperContext.getXSDHelper()).addGlobalProperty(nextQName,nextSDOProperty,false);
    }
    Iterator<java.util.List<GlobalRef>> globalRefsIter=getGlobalRefs().values().iterator();
    while (globalRefsIter.hasNext()) {
      java.util.List<GlobalRef> nextList=globalRefsIter.next();
      if (nextList.size() > 0) {
        GlobalRef ref=nextList.get(0);
        throw SDOException.referencedPropertyNotFound(((SDOProperty)ref.getProperty()).getUri(),ref.getProperty().getName());
      }
    }
  }
  return returnList;
}