Program: 51306
Project: 51306
Buggy source:
/** 
 * Creates a <code>RolapCube</code> from a virtual cube.
 */
RolapCube(RolapSchema schema,MondrianDef.Schema xmlSchema,MondrianDef.VirtualCube xmlVirtualCube,boolean load){
  this(schema,xmlSchema,xmlVirtualCube.name,true,null,xmlVirtualCube.dimensions,load);
  RolapLevel measuresLevel=this.measuresHierarchy.newMeasuresLevel();
  List<RolapVirtualCubeMeasure> origMeasureList=new ArrayList<RolapVirtualCubeMeasure>();
  List<MondrianDef.CalculatedMember> origCalcMeasureList=new ArrayList<MondrianDef.CalculatedMember>();
  CubeComparator cubeComparator=new CubeComparator();
  Map<RolapCube,List<MondrianDef.CalculatedMember>> calculatedMembersMap=new TreeMap<RolapCube,List<MondrianDef.CalculatedMember>>(cubeComparator);
  Member defaultMeasure=null;
  for (  MondrianDef.VirtualCubeMeasure xmlMeasure : xmlVirtualCube.measures) {
    RolapCube cube=schema.lookupCube(xmlMeasure.cubeName);
    Member[] cubeMeasures=cube.getMeasures();
    boolean found=false;
    for (    Member cubeMeasure : cubeMeasures) {
      if (cubeMeasure.getUniqueName().equals(xmlMeasure.name)) {
        if (cubeMeasure.getName().equalsIgnoreCase(xmlVirtualCube.defaultMeasure)) {
          defaultMeasure=cubeMeasure;
        }
        found=true;
        if (cubeMeasure instanceof RolapCalculatedMember) {
          MondrianDef.CalculatedMember calcMember=schema.lookupXmlCalculatedMember(xmlMeasure.name,xmlMeasure.cubeName);
          if (calcMember == null) {
            throw Util.newInternal("String_Node_Str" + xmlMeasure.name + "String_Node_Str"+ xmlMeasure.cubeName+ "String_Node_Str");
          }
          List<MondrianDef.CalculatedMember> memberList=calculatedMembersMap.get(cube);
          if (memberList == null) {
            memberList=new ArrayList<MondrianDef.CalculatedMember>();
          }
          memberList.add(calcMember);
          origCalcMeasureList.add(calcMember);
          calculatedMembersMap.put(cube,memberList);
        }
 else {
          RolapVirtualCubeMeasure virtualCubeMeasure=new RolapVirtualCubeMeasure(null,measuresLevel,(RolapStoredMeasure)cubeMeasure);
          Boolean visible=xmlMeasure.visible;
          if (visible == null) {
            visible=Boolean.TRUE;
          }
          virtualCubeMeasure.setProperty(Property.VISIBLE.name,visible);
          origMeasureList.add(virtualCubeMeasure);
        }
        break;
      }
    }
    if (!found) {
      throw Util.newInternal("String_Node_Str" + xmlMeasure.name + "String_Node_Str"+ xmlMeasure.cubeName+ "String_Node_Str");
    }
  }
  init(xmlVirtualCube.dimensions);
  List<RolapVirtualCubeMeasure> modifiedMeasureList=new ArrayList<RolapVirtualCubeMeasure>(origMeasureList);
  for (  Object o : calculatedMembersMap.keySet()) {
    RolapCube baseCube=(RolapCube)o;
    List<MondrianDef.CalculatedMember> calculatedMemberList=calculatedMembersMap.get(baseCube);
    Query queryExp=resolveCalcMembers(calculatedMemberList.toArray(new MondrianDef.CalculatedMember[calculatedMemberList.size()]),new MondrianDef.NamedSet[0],baseCube,false);
    MeasureFinder measureFinder=new MeasureFinder(this,baseCube,measuresLevel);
    queryExp.accept(measureFinder);
    modifiedMeasureList.addAll(measureFinder.getMeasuresFound());
  }
  List<MondrianDef.CalculatedMember> calculatedMemberList=new ArrayList<MondrianDef.CalculatedMember>();
  for (  Object o : calculatedMembersMap.keySet()) {
    RolapCube baseCube=(RolapCube)o;
    calculatedMemberList.addAll(calculatedMembersMap.get(baseCube));
  }
  calculatedMemberList.addAll(Arrays.asList(xmlVirtualCube.calculatedMembers));
  RolapMember[] measures=modifiedMeasureList.toArray(new RolapMember[modifiedMeasureList.size()]);
  this.measuresHierarchy.setMemberReader(new CacheMemberReader(new MeasureMemberSource(this.measuresHierarchy,measures)));
  createCalcMembersAndNamedSets(calculatedMemberList.toArray(new MondrianDef.CalculatedMember[calculatedMemberList.size()]),new MondrianDef.NamedSet[0],new ArrayList<Member>(),new ArrayList<Formula>(),this,false);
  measures=origMeasureList.toArray(new RolapMember[origMeasureList.size()]);
  this.measuresHierarchy.setMemberReader(new CacheMemberReader(new MeasureMemberSource(this.measuresHierarchy,measures)));
  this.measuresHierarchy.setDefaultMember(defaultMeasure);
  List<Formula> finalCalcMemberList=new ArrayList<Formula>();
  for (  Formula calculatedMember : calculatedMembers) {
    if (findOriginalMembers(calculatedMember,origCalcMeasureList,finalCalcMemberList)) {
      continue;
    }
    findOriginalMembers(calculatedMember,Arrays.asList(xmlVirtualCube.calculatedMembers),finalCalcMemberList);
  }
  calculatedMembers=finalCalcMemberList.toArray(new Formula[finalCalcMemberList.size()]);
  for (  Formula calcMember : finalCalcMemberList) {
    if (calcMember.getName().equalsIgnoreCase(xmlVirtualCube.defaultMeasure)) {
      this.measuresHierarchy.setDefaultMember(calcMember.getMdxMember());
      break;
    }
  }
}

Fixed version (ground truth):
/** 
 * Creates a <code>RolapCube</code> from a virtual cube.
 */
RolapCube(RolapSchema schema,MondrianDef.Schema xmlSchema,MondrianDef.VirtualCube xmlVirtualCube,boolean load){
  this(schema,xmlSchema,xmlVirtualCube.name,true,null,xmlVirtualCube.dimensions,load);
  RolapLevel measuresLevel=this.measuresHierarchy.newMeasuresLevel();
  List<RolapVirtualCubeMeasure> origMeasureList=new ArrayList<RolapVirtualCubeMeasure>();
  List<MondrianDef.CalculatedMember> origCalcMeasureList=new ArrayList<MondrianDef.CalculatedMember>();
  CubeComparator cubeComparator=new CubeComparator();
  Map<RolapCube,List<MondrianDef.CalculatedMember>> calculatedMembersMap=new TreeMap<RolapCube,List<MondrianDef.CalculatedMember>>(cubeComparator);
  Member defaultMeasure=null;
  for (  MondrianDef.VirtualCubeMeasure xmlMeasure : xmlVirtualCube.measures) {
    RolapCube cube=schema.lookupCube(xmlMeasure.cubeName);
    Member[] cubeMeasures=cube.getMeasures();
    boolean found=false;
    for (    Member cubeMeasure : cubeMeasures) {
      if (cubeMeasure.getUniqueName().equals(xmlMeasure.name)) {
        if (cubeMeasure.getName().equalsIgnoreCase(xmlVirtualCube.defaultMeasure)) {
          defaultMeasure=cubeMeasure;
        }
        found=true;
        if (cubeMeasure instanceof RolapCalculatedMember) {
          MondrianDef.CalculatedMember calcMember=schema.lookupXmlCalculatedMember(xmlMeasure.name,xmlMeasure.cubeName);
          if (calcMember == null) {
            throw Util.newInternal("String_Node_Str" + xmlMeasure.name + "String_Node_Str"+ xmlMeasure.cubeName+ "String_Node_Str");
          }
          List<MondrianDef.CalculatedMember> memberList=calculatedMembersMap.get(cube);
          if (memberList == null) {
            memberList=new ArrayList<MondrianDef.CalculatedMember>();
          }
          memberList.add(calcMember);
          origCalcMeasureList.add(calcMember);
          calculatedMembersMap.put(cube,memberList);
        }
 else {
          RolapVirtualCubeMeasure virtualCubeMeasure=new RolapVirtualCubeMeasure(null,measuresLevel,(RolapStoredMeasure)cubeMeasure);
          Boolean visible=xmlMeasure.visible;
          if (visible == null) {
            visible=Boolean.TRUE;
          }
          virtualCubeMeasure.setProperty(Property.VISIBLE.name,visible);
          virtualCubeMeasure.setProperty(Property.CAPTION.name,cubeMeasure.getCaption());
          origMeasureList.add(virtualCubeMeasure);
        }
        break;
      }
    }
    if (!found) {
      throw Util.newInternal("String_Node_Str" + xmlMeasure.name + "String_Node_Str"+ xmlMeasure.cubeName+ "String_Node_Str");
    }
  }
  init(xmlVirtualCube.dimensions);
  List<RolapVirtualCubeMeasure> modifiedMeasureList=new ArrayList<RolapVirtualCubeMeasure>(origMeasureList);
  for (  Object o : calculatedMembersMap.keySet()) {
    RolapCube baseCube=(RolapCube)o;
    List<MondrianDef.CalculatedMember> calculatedMemberList=calculatedMembersMap.get(baseCube);
    Query queryExp=resolveCalcMembers(calculatedMemberList.toArray(new MondrianDef.CalculatedMember[calculatedMemberList.size()]),new MondrianDef.NamedSet[0],baseCube,false);
    MeasureFinder measureFinder=new MeasureFinder(this,baseCube,measuresLevel);
    queryExp.accept(measureFinder);
    modifiedMeasureList.addAll(measureFinder.getMeasuresFound());
  }
  List<MondrianDef.CalculatedMember> calculatedMemberList=new ArrayList<MondrianDef.CalculatedMember>();
  for (  Object o : calculatedMembersMap.keySet()) {
    RolapCube baseCube=(RolapCube)o;
    calculatedMemberList.addAll(calculatedMembersMap.get(baseCube));
  }
  calculatedMemberList.addAll(Arrays.asList(xmlVirtualCube.calculatedMembers));
  RolapMember[] measures=modifiedMeasureList.toArray(new RolapMember[modifiedMeasureList.size()]);
  this.measuresHierarchy.setMemberReader(new CacheMemberReader(new MeasureMemberSource(this.measuresHierarchy,measures)));
  createCalcMembersAndNamedSets(calculatedMemberList.toArray(new MondrianDef.CalculatedMember[calculatedMemberList.size()]),new MondrianDef.NamedSet[0],new ArrayList<Member>(),new ArrayList<Formula>(),this,false);
  measures=origMeasureList.toArray(new RolapMember[origMeasureList.size()]);
  this.measuresHierarchy.setMemberReader(new CacheMemberReader(new MeasureMemberSource(this.measuresHierarchy,measures)));
  this.measuresHierarchy.setDefaultMember(defaultMeasure);
  List<Formula> finalCalcMemberList=new ArrayList<Formula>();
  for (  Formula calculatedMember : calculatedMembers) {
    if (findOriginalMembers(calculatedMember,origCalcMeasureList,finalCalcMemberList)) {
      continue;
    }
    findOriginalMembers(calculatedMember,Arrays.asList(xmlVirtualCube.calculatedMembers),finalCalcMemberList);
  }
  calculatedMembers=finalCalcMemberList.toArray(new Formula[finalCalcMemberList.size()]);
  for (  Formula calcMember : finalCalcMemberList) {
    if (calcMember.getName().equalsIgnoreCase(xmlVirtualCube.defaultMeasure)) {
      this.measuresHierarchy.setDefaultMember(calcMember.getMdxMember());
      break;
    }
  }
}