Program: 74774
Project: 74774
Buggy source:
/** 
 * @return
 * @throws DataException
 */
protected DimLevel[] populateAggrLevels() throws DataException {
  String bindingName=OlapExpressionCompiler.getReferencedScriptObject(expr,"String_Node_Str");
  if (bindingName == null)   return null;
  for (Iterator it=queryDefn.getBindings().iterator(); it.hasNext(); ) {
    IBinding binding=(IBinding)it.next();
    if (binding.getBindingName().equals(bindingName)) {
      List aggrs=binding.getAggregatOns();
      if (aggrs.size() == 0) {
        if (OlapExpressionCompiler.getReferencedScriptObject(binding.getExpression(),"String_Node_Str") != null)         return null;
        List levelList=new ArrayList();
        IEdgeDefinition rowEdge=queryDefn.getEdge(ICubeQueryDefinition.ROW_EDGE);
        List rowDims=rowEdge.getDimensions();
        for (Iterator i=rowDims.iterator(); i.hasNext(); ) {
          IDimensionDefinition dim=(IDimensionDefinition)i.next();
          IHierarchyDefinition hirarchy=(IHierarchyDefinition)dim.getHierarchy().get(0);
          for (Iterator j=hirarchy.getLevels().iterator(); j.hasNext(); ) {
            ILevelDefinition level=(ILevelDefinition)j.next();
            levelList.add(new DimLevel(dim.getName(),level.getName()));
          }
        }
        IEdgeDefinition colEdge=queryDefn.getEdge(ICubeQueryDefinition.COLUMN_EDGE);
        List colDims=colEdge.getDimensions();
        for (Iterator i=colDims.iterator(); i.hasNext(); ) {
          IDimensionDefinition dim=(IDimensionDefinition)i.next();
          IHierarchyDefinition hirarchy=(IHierarchyDefinition)dim.getHierarchy().get(0);
          for (Iterator j=hirarchy.getLevels().iterator(); j.hasNext(); ) {
            ILevelDefinition level=(ILevelDefinition)j.next();
            levelList.add(new DimLevel(dim.getName(),level.getName()));
          }
        }
        DimLevel[] levels=new DimLevel[levelList.size()];
        levelList.toArray(levels);
        return levels;
      }
 else {
        DimLevel[] levels=new DimLevel[aggrs.size()];
        for (int i=0; i < aggrs.size(); i++) {
          levels[i]=OlapExpressionUtil.getTargetDimLevel(aggrs.get(i).toString());
        }
        return levels;
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * @return
 * @throws DataException
 */
protected DimLevel[] populateAggrLevels() throws DataException {
  String bindingName=OlapExpressionCompiler.getReferencedScriptObject(expr,"String_Node_Str");
  if (bindingName == null)   return null;
  for (Iterator it=queryDefn.getBindings().iterator(); it.hasNext(); ) {
    IBinding binding=(IBinding)it.next();
    if (binding.getBindingName().equals(bindingName)) {
      List aggrs=binding.getAggregatOns();
      if (aggrs.size() == 0) {
        if (OlapExpressionCompiler.getReferencedScriptObject(binding.getExpression(),"String_Node_Str") != null)         return null;
        List levelList=new ArrayList();
        IEdgeDefinition rowEdge=queryDefn.getEdge(ICubeQueryDefinition.ROW_EDGE);
        populateDimLevel(levelList,rowEdge);
        IEdgeDefinition colEdge=queryDefn.getEdge(ICubeQueryDefinition.COLUMN_EDGE);
        populateDimLevel(levelList,colEdge);
        DimLevel[] levels=new DimLevel[levelList.size()];
        levelList.toArray(levels);
        return levels;
      }
 else {
        DimLevel[] levels=new DimLevel[aggrs.size()];
        for (int i=0; i < aggrs.size(); i++) {
          levels[i]=OlapExpressionUtil.getTargetDimLevel(aggrs.get(i).toString());
        }
        return levels;
      }
    }
  }
  return null;
}