Program: 51192
Project: 51192
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;
  this.cubeUsages=new RolapCubeUsages(xmlVirtualCube.cubeUsage);
  for (  MondrianDef.VirtualCubeMeasure xmlMeasure : xmlVirtualCube.measures) {
    RolapCube cube=schema.lookupCube(xmlMeasure.cubeName);
    List<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,Collections.<MondrianDef.NamedSet>emptyList(),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));
  setMeasuresHierarchyMemberReader(new CacheMemberReader(new MeasureMemberSource(this.measuresHierarchy,Util.<RolapMember>cast(modifiedMeasureList))));
  createCalcMembersAndNamedSets(calculatedMemberList,Arrays.asList(xmlVirtualCube.namedSets),new ArrayList<RolapMember>(),new ArrayList<Formula>(),this,false);
  setMeasuresHierarchyMemberReader(new CacheMemberReader(new MeasureMemberSource(this.measuresHierarchy,Util.<RolapMember>cast(origMeasureList))));
  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,xmlVirtualCube.caption,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;
  this.cubeUsages=new RolapCubeUsages(xmlVirtualCube.cubeUsage);
  for (  MondrianDef.VirtualCubeMeasure xmlMeasure : xmlVirtualCube.measures) {
    RolapCube cube=schema.lookupCube(xmlMeasure.cubeName);
    List<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,Collections.<MondrianDef.NamedSet>emptyList(),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));
  setMeasuresHierarchyMemberReader(new CacheMemberReader(new MeasureMemberSource(this.measuresHierarchy,Util.<RolapMember>cast(modifiedMeasureList))));
  createCalcMembersAndNamedSets(calculatedMemberList,Arrays.asList(xmlVirtualCube.namedSets),new ArrayList<RolapMember>(),new ArrayList<Formula>(),this,false);
  setMeasuresHierarchyMemberReader(new CacheMemberReader(new MeasureMemberSource(this.measuresHierarchy,Util.<RolapMember>cast(origMeasureList))));
  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;
    }
  }
}