Program: 25106
Project: 25106
Buggy source:
/** 
 * Followed algorithm: <pre> Map&lt;DBTable,ADQLTable&gt; mapTables; For each ADQLTable t if (t.isSubQuery()) dbTable = generateDBTable(t.getSubQuery, t.getAlias()); else dbTable = resolveTable(t); t.setDBLink(dbTable); dbTables.put(t, dbTable); End For each SelectAllColumns c table = c.getAdqlTable(); if (table != null){ dbTable = resolveTable(table); if (dbTable == null) dbTable = query.getFrom().getTablesByAlias(table.getTableName(), table.isCaseSensitive(IdentifierField.TABLE)); if (dbTable == null) throw new UnresolvedTableException(table); table.setDBLink(dbTable); } End SearchColumnList list = query.getFrom().getDBColumns(); For each ADQLColumn c dbColumn = resolveColumn(c, list); c.setDBLink(dbColumn); c.setAdqlTable(mapTables.get(dbColumn.getTable())); End For each ColumnReference colRef checkColumnReference(colRef, query.getSelect(), list); End </pre>
 * @param query			The query to check.
 * @param fathersList	List of all columns available in the father query.
 * @throws UnresolvedIdentifiersException	An {@link UnresolvedIdentifiersException} if some tables or columns can not be resolved.
 * @since 1.2
 * @see #resolveTable(ADQLTable)
 * @see #generateDBTable(ADQLQuery,String)
 * @see #resolveColumn(ADQLColumn,SearchColumnList,Stack)
 * @see #checkColumnReference(ColumnReference,ClauseSelect,SearchColumnList)
 */
protected void check(final ADQLQuery query,Stack<SearchColumnList> fathersList) throws UnresolvedIdentifiersException {
  UnresolvedIdentifiersException errors=new UnresolvedIdentifiersException();
  HashMap<DBTable,ADQLTable> mapTables=new HashMap<DBTable,ADQLTable>();
  ISearchHandler sHandler;
  sHandler=new SearchTableHandler();
  sHandler.search(query.getFrom());
  for (  ADQLObject result : sHandler) {
    try {
      ADQLTable table=(ADQLTable)result;
      DBTable dbTable=null;
      if (table.isSubQuery()) {
        check(table.getSubQuery(),fathersList);
        dbTable=generateDBTable(table.getSubQuery(),table.getAlias());
      }
 else {
        dbTable=resolveTable(table);
        if (table.hasAlias())         dbTable=dbTable.copy(dbTable.getDBName(),table.getAlias());
      }
      table.setDBLink(dbTable);
      mapTables.put(dbTable,table);
    }
 catch (    ParseException pe) {
      errors.addException(pe);
    }
  }
  sHandler=new SearchWildCardHandler();
  sHandler.search(query.getSelect());
  for (  ADQLObject result : sHandler) {
    try {
      SelectAllColumns wildcard=(SelectAllColumns)result;
      ADQLTable table=wildcard.getAdqlTable();
      DBTable dbTable=null;
      if (table.getTableName() != null && table.getSchemaName() == null) {
        ArrayList<ADQLTable> tables=query.getFrom().getTablesByAlias(table.getTableName(),table.isCaseSensitive(IdentifierField.TABLE));
        if (tables.size() == 1)         dbTable=tables.get(0).getDBLink();
      }
      if (dbTable == null)       dbTable=resolveTable(table);
      wildcard.setAdqlTable(mapTables.get(dbTable));
    }
 catch (    ParseException pe) {
      errors.addException(pe);
    }
  }
  SearchColumnList list;
  try {
    list=query.getFrom().getDBColumns();
  }
 catch (  ParseException pe) {
    errors.addException(pe);
    list=new SearchColumnList();
  }
  sHandler=new SearchColumnHandler();
  sHandler.search(query);
  for (  ADQLObject result : sHandler) {
    try {
      ADQLColumn adqlColumn=(ADQLColumn)result;
      DBColumn dbColumn=resolveColumn(adqlColumn,list,fathersList);
      adqlColumn.setDBLink(dbColumn);
      adqlColumn.setAdqlTable(mapTables.get(dbColumn.getTable()));
    }
 catch (    ParseException pe) {
      errors.addException(pe);
    }
  }
  sHandler=new SearchColReferenceHandler();
  sHandler.search(query);
  ClauseSelect select=query.getSelect();
  for (  ADQLObject result : sHandler) {
    try {
      ColumnReference colRef=(ColumnReference)result;
      DBColumn dbColumn=checkColumnReference(colRef,select,list);
      colRef.setDBLink(dbColumn);
      if (dbColumn != null)       colRef.setAdqlTable(mapTables.get(dbColumn.getTable()));
    }
 catch (    ParseException pe) {
      errors.addException(pe);
    }
  }
  sHandler=new SearchSubQueryHandler();
  sHandler.search(query);
  if (sHandler.getNbMatch() > 0) {
    if (fathersList == null)     fathersList=new Stack<SearchColumnList>();
    fathersList.push(list);
    for (    ADQLObject result : sHandler) {
      try {
        check((ADQLQuery)result,fathersList);
      }
 catch (      UnresolvedIdentifiersException uie) {
        Iterator<ParseException> itPe=uie.getErrors();
        while (itPe.hasNext())         errors.addException(itPe.next());
      }
    }
    fathersList.pop();
  }
  if (errors.getNbErrors() > 0)   throw errors;
}

Fixed version (ground truth):
/** 
 * Followed algorithm: <pre> Map&lt;DBTable,ADQLTable&gt; mapTables; For each ADQLTable t if (t.isSubQuery()) dbTable = generateDBTable(t.getSubQuery, t.getAlias()); else dbTable = resolveTable(t); t.setDBLink(dbTable); dbTables.put(t, dbTable); End For each SelectAllColumns c table = c.getAdqlTable(); if (table != null){ dbTable = resolveTable(table); if (dbTable == null) dbTable = query.getFrom().getTablesByAlias(table.getTableName(), table.isCaseSensitive(IdentifierField.TABLE)); if (dbTable == null) throw new UnresolvedTableException(table); table.setDBLink(dbTable); } End SearchColumnList list = query.getFrom().getDBColumns(); For each ADQLColumn c dbColumn = resolveColumn(c, list); c.setDBLink(dbColumn); c.setAdqlTable(mapTables.get(dbColumn.getTable())); End For each ColumnReference colRef checkColumnReference(colRef, query.getSelect(), list); End </pre>
 * @param query			The query to check.
 * @param fathersList	List of all columns available in the father query.
 * @throws UnresolvedIdentifiersException	An {@link UnresolvedIdentifiersException} if some tables or columns can not be resolved.
 * @since 1.2
 * @see #resolveTable(ADQLTable)
 * @see #generateDBTable(ADQLQuery,String)
 * @see #resolveColumn(ADQLColumn,SearchColumnList,Stack)
 * @see #checkColumnReference(ColumnReference,ClauseSelect,SearchColumnList)
 */
protected void check(final ADQLQuery query,Stack<SearchColumnList> fathersList) throws UnresolvedIdentifiersException {
  UnresolvedIdentifiersException errors=new UnresolvedIdentifiersException();
  HashMap<DBTable,ADQLTable> mapTables=new HashMap<DBTable,ADQLTable>();
  ISearchHandler sHandler;
  sHandler=new SearchTableHandler();
  sHandler.search(query.getFrom());
  for (  ADQLObject result : sHandler) {
    try {
      ADQLTable table=(ADQLTable)result;
      DBTable dbTable=null;
      if (table.isSubQuery()) {
        check(table.getSubQuery(),fathersList);
        dbTable=generateDBTable(table.getSubQuery(),table.getAlias());
      }
 else {
        dbTable=resolveTable(table);
        if (table.hasAlias())         dbTable=dbTable.copy(null,table.getAlias());
      }
      table.setDBLink(dbTable);
      mapTables.put(dbTable,table);
    }
 catch (    ParseException pe) {
      errors.addException(pe);
    }
  }
  sHandler=new SearchWildCardHandler();
  sHandler.search(query.getSelect());
  for (  ADQLObject result : sHandler) {
    try {
      SelectAllColumns wildcard=(SelectAllColumns)result;
      ADQLTable table=wildcard.getAdqlTable();
      DBTable dbTable=null;
      if (table.getTableName() != null && table.getSchemaName() == null) {
        ArrayList<ADQLTable> tables=query.getFrom().getTablesByAlias(table.getTableName(),table.isCaseSensitive(IdentifierField.TABLE));
        if (tables.size() == 1)         dbTable=tables.get(0).getDBLink();
      }
      if (dbTable == null)       dbTable=resolveTable(table);
      wildcard.setAdqlTable(mapTables.get(dbTable));
    }
 catch (    ParseException pe) {
      errors.addException(pe);
    }
  }
  SearchColumnList list;
  try {
    list=query.getFrom().getDBColumns();
  }
 catch (  ParseException pe) {
    errors.addException(pe);
    list=new SearchColumnList();
  }
  sHandler=new SearchColumnHandler();
  sHandler.search(query);
  for (  ADQLObject result : sHandler) {
    try {
      ADQLColumn adqlColumn=(ADQLColumn)result;
      DBColumn dbColumn=resolveColumn(adqlColumn,list,fathersList);
      adqlColumn.setDBLink(dbColumn);
      adqlColumn.setAdqlTable(mapTables.get(dbColumn.getTable()));
    }
 catch (    ParseException pe) {
      errors.addException(pe);
    }
  }
  sHandler=new SearchColReferenceHandler();
  sHandler.search(query);
  ClauseSelect select=query.getSelect();
  for (  ADQLObject result : sHandler) {
    try {
      ColumnReference colRef=(ColumnReference)result;
      DBColumn dbColumn=checkColumnReference(colRef,select,list);
      colRef.setDBLink(dbColumn);
      if (dbColumn != null)       colRef.setAdqlTable(mapTables.get(dbColumn.getTable()));
    }
 catch (    ParseException pe) {
      errors.addException(pe);
    }
  }
  sHandler=new SearchSubQueryHandler();
  sHandler.search(query);
  if (sHandler.getNbMatch() > 0) {
    if (fathersList == null)     fathersList=new Stack<SearchColumnList>();
    fathersList.push(list);
    for (    ADQLObject result : sHandler) {
      try {
        check((ADQLQuery)result,fathersList);
      }
 catch (      UnresolvedIdentifiersException uie) {
        Iterator<ParseException> itPe=uie.getErrors();
        while (itPe.hasNext())         errors.addException(itPe.next());
      }
    }
    fathersList.pop();
  }
  if (errors.getNbErrors() > 0)   throw errors;
}