Program: 101963
Project: 101963
Buggy source:
/** 
 * @param metadata
 * @param query
 * @throws Exception
 */
public void resolveWith(TempMetadataAdapter metadata,QueryCommand query) throws Exception {
  if (query.getWith() == null) {
    return;
  }
  LinkedHashSet<GroupSymbol> discoveredGroups=new LinkedHashSet<GroupSymbol>();
  for (  WithQueryCommand obj : query.getWith()) {
    QueryCommand queryExpression=obj.getCommand();
    getQueryResolver().setChildMetadata(queryExpression,query);
    QueryCommand recursive=null;
    if (getTeiidVersion().isGreaterThanOrEqualTo(Version.TEIID_8_10)) {
      try {
        getQueryResolver().resolveCommand(queryExpression,metadata.getMetadata(),false);
      }
 catch (      QueryResolverException e) {
        if (!(queryExpression instanceof SetQuery)) {
          throw e;
        }
        SetQuery setQuery=(SetQuery)queryExpression;
        if (setQuery.getOperation() != Operation.UNION || setQuery.getLimit() != null || setQuery.getOrderBy() != null || setQuery.getOption() != null) {
          throw e;
        }
        getQueryResolver().resolveCommand(queryExpression,metadata.getMetadata(),false);
        recursive=setQuery.getRightQuery();
      }
    }
 else {
      getQueryResolver().resolveCommand(queryExpression,metadata.getMetadata(),false);
    }
    if (!discoveredGroups.add(obj.getGroupSymbol())) {
      throw new QueryResolverException(Messages.gs(Messages.TEIID.TEIID30101,obj.getGroupSymbol()));
    }
    List<? extends Expression> projectedSymbols=obj.getCommand().getProjectedSymbols();
    if (obj.getColumns() != null && !obj.getColumns().isEmpty()) {
      if (obj.getColumns().size() != projectedSymbols.size()) {
        throw new QueryResolverException(Messages.gs(Messages.TEIID.TEIID30102,obj.getGroupSymbol()));
      }
      Iterator<ElementSymbol> iter=obj.getColumns().iterator();
      for (      Expression singleElementSymbol : projectedSymbols) {
        ElementSymbol es=iter.next();
        es.setType(singleElementSymbol.getType());
      }
      projectedSymbols=obj.getColumns();
    }
    TempMetadataID id=ResolverUtil.addTempGroup(metadata,obj.getGroupSymbol(),projectedSymbols,true);
    obj.getGroupSymbol().setMetadataID(metadata.getMetadataStore().getTempGroupID(obj.getGroupSymbol().getName()));
    obj.getGroupSymbol().setIsTempTable(true);
    List<GroupSymbol> groups=Collections.singletonList(obj.getGroupSymbol());
    ResolverVisitor visitor=new ResolverVisitor(obj.getTeiidVersion());
    if (obj.getColumns() != null && !obj.getColumns().isEmpty()) {
      for (      Expression singleElementSymbol : projectedSymbols) {
        visitor.resolveLanguageObject(singleElementSymbol,groups,metadata);
      }
    }
    if (obj.getColumns() != null && !obj.getColumns().isEmpty()) {
      Iterator<ElementSymbol> iter=obj.getColumns().iterator();
      for (      TempMetadataID colid : id.getElements()) {
        ElementSymbol es=iter.next();
        es.setMetadataID(colid);
        es.setGroupSymbol(obj.getGroupSymbol());
      }
    }
    if (recursive != null) {
      getQueryResolver().setChildMetadata(recursive,query);
      getQueryResolver().resolveCommand(recursive,metadata.getMetadata(),false);
      new SetQueryResolver(getQueryResolver()).resolveSetQuery(metadata,false,(SetQuery)queryExpression,((SetQuery)queryExpression).getLeftQuery(),recursive);
      obj.setRecursive(true);
    }
  }
}

Fixed version (ground truth):
/** 
 * @param metadata
 * @param query
 * @throws Exception
 */
public void resolveWith(TempMetadataAdapter metadata,QueryCommand query) throws Exception {
  if (query.getWith() == null) {
    return;
  }
  LinkedHashSet<GroupSymbol> discoveredGroups=new LinkedHashSet<GroupSymbol>();
  for (  WithQueryCommand obj : query.getWith()) {
    QueryCommand queryExpression=obj.getCommand();
    getQueryResolver().setChildMetadata(queryExpression,query);
    QueryCommand recursive=null;
    if (getTeiidVersion().isGreaterThanOrEqualTo(Version.TEIID_8_10)) {
      try {
        getQueryResolver().resolveCommand(queryExpression,metadata.getMetadata(),false);
      }
 catch (      QueryResolverException e) {
        if (!(queryExpression instanceof SetQuery)) {
          throw e;
        }
        SetQuery setQuery=(SetQuery)queryExpression;
        if (setQuery.getOperation() != Operation.UNION || setQuery.getLimit() != null || setQuery.getOrderBy() != null || setQuery.getOption() != null) {
          throw e;
        }
        getQueryResolver().resolveCommand(setQuery.getLeftQuery(),metadata.getMetadata(),false);
        recursive=setQuery.getRightQuery();
      }
    }
 else {
      getQueryResolver().resolveCommand(queryExpression,metadata.getMetadata(),false);
    }
    if (!discoveredGroups.add(obj.getGroupSymbol())) {
      throw new QueryResolverException(Messages.gs(Messages.TEIID.TEIID30101,obj.getGroupSymbol()));
    }
    List<? extends Expression> projectedSymbols=obj.getCommand().getProjectedSymbols();
    if (obj.getColumns() != null && !obj.getColumns().isEmpty()) {
      if (obj.getColumns().size() != projectedSymbols.size()) {
        throw new QueryResolverException(Messages.gs(Messages.TEIID.TEIID30102,obj.getGroupSymbol()));
      }
      Iterator<ElementSymbol> iter=obj.getColumns().iterator();
      for (      Expression singleElementSymbol : projectedSymbols) {
        ElementSymbol es=iter.next();
        es.setType(singleElementSymbol.getType());
      }
      projectedSymbols=obj.getColumns();
    }
    TempMetadataID id=ResolverUtil.addTempGroup(metadata,obj.getGroupSymbol(),projectedSymbols,true);
    obj.getGroupSymbol().setMetadataID(metadata.getMetadataStore().getTempGroupID(obj.getGroupSymbol().getName()));
    obj.getGroupSymbol().setIsTempTable(true);
    List<GroupSymbol> groups=Collections.singletonList(obj.getGroupSymbol());
    ResolverVisitor visitor=new ResolverVisitor(obj.getTeiidVersion());
    if (obj.getColumns() != null && !obj.getColumns().isEmpty()) {
      for (      Expression singleElementSymbol : projectedSymbols) {
        visitor.resolveLanguageObject(singleElementSymbol,groups,metadata);
      }
    }
    if (obj.getColumns() != null && !obj.getColumns().isEmpty()) {
      Iterator<ElementSymbol> iter=obj.getColumns().iterator();
      for (      TempMetadataID colid : id.getElements()) {
        ElementSymbol es=iter.next();
        es.setMetadataID(colid);
        es.setGroupSymbol(obj.getGroupSymbol());
      }
    }
    if (recursive != null) {
      getQueryResolver().setChildMetadata(recursive,query);
      getQueryResolver().resolveCommand(recursive,metadata.getMetadata(),false);
      new SetQueryResolver(getQueryResolver()).resolveSetQuery(metadata,false,(SetQuery)queryExpression,((SetQuery)queryExpression).getLeftQuery(),recursive);
      obj.setRecursive(true);
    }
  }
}