Program: 51291
Project: 51291
Buggy source:
public Calc compileCall(ResolvedFunCall call,ExpCompiler compiler){
  final Exp[] args=call.getArgs();
  final LevelCalc levelCalc;
  final MemberCalc memberCalc;
switch (args.length) {
case 0:
    memberCalc=new DimensionCurrentMemberCalc(compiler.getEvaluator().getCube().getTimeDimension());
  levelCalc=null;
break;
case 1:
levelCalc=compiler.compileLevel(call.getArg(0));
memberCalc=new DimensionCurrentMemberCalc(compiler.getEvaluator().getCube().getTimeDimension());
break;
default :
levelCalc=compiler.compileLevel(call.getArg(0));
memberCalc=compiler.compileMember(call.getArg(1));
break;
}
if (levelCalc != null) {
final Dimension memberDimension=memberCalc.getType().getDimension();
final Dimension levelDimension=levelCalc.getType().getDimension();
if (!memberDimension.equals(levelDimension)) {
throw MondrianResource.instance().FunctionMbrAndLevelHierarchyMismatch.ex(opening ? "String_Node_Str" : "String_Node_Str",levelDimension.getUniqueName(),memberDimension.getUniqueName());
}
}
return new AbstractMemberCalc(call,new Calc[]{levelCalc,memberCalc}){
public Member evaluateMember(Evaluator evaluator){
Member member=memberCalc.evaluateMember(evaluator);
Level level;
if (levelCalc == null) {
int targetDepth=member.getLevel().getDepth() + 1;
Level[] levels=member.getHierarchy().getLevels();
if (levels.length <= targetDepth) {
return member.getHierarchy().getNullMember();
}
level=levels[targetDepth];
}
 else {
level=levelCalc.evaluateLevel(evaluator);
}
if (level.getDepth() < member.getLevel().getDepth()) {
return member.getHierarchy().getNullMember();
}
if (level == member.getLevel()) {
return member;
}
return getDescendant(evaluator.getSchemaReader(),member,level,opening);
}
}
;
}

Fixed version (ground truth):
public Calc compileCall(ResolvedFunCall call,ExpCompiler compiler){
  final Exp[] args=call.getArgs();
  final LevelCalc levelCalc;
  final MemberCalc memberCalc;
  Dimension defaultTimeDimension=null;
switch (args.length) {
case 0:
    defaultTimeDimension=compiler.getEvaluator().getCube().getTimeDimension();
  if (defaultTimeDimension == null) {
    throw MondrianResource.instance().NoTimeDimensionInCube.ex(getName());
  }
memberCalc=new DimensionCurrentMemberCalc(defaultTimeDimension);
levelCalc=null;
break;
case 1:
defaultTimeDimension=compiler.getEvaluator().getCube().getTimeDimension();
if (defaultTimeDimension == null) {
throw MondrianResource.instance().NoTimeDimensionInCube.ex(getName());
}
levelCalc=compiler.compileLevel(call.getArg(0));
memberCalc=new DimensionCurrentMemberCalc(defaultTimeDimension);
break;
default :
levelCalc=compiler.compileLevel(call.getArg(0));
memberCalc=compiler.compileMember(call.getArg(1));
break;
}
if (levelCalc != null) {
final Dimension memberDimension=memberCalc.getType().getDimension();
final Dimension levelDimension=levelCalc.getType().getDimension();
if (!memberDimension.equals(levelDimension)) {
throw MondrianResource.instance().FunctionMbrAndLevelHierarchyMismatch.ex(opening ? "String_Node_Str" : "String_Node_Str",levelDimension.getUniqueName(),memberDimension.getUniqueName());
}
}
return new AbstractMemberCalc(call,new Calc[]{levelCalc,memberCalc}){
public Member evaluateMember(Evaluator evaluator){
Member member=memberCalc.evaluateMember(evaluator);
Level level;
if (levelCalc == null) {
int targetDepth=member.getLevel().getDepth() + 1;
Level[] levels=member.getHierarchy().getLevels();
if (levels.length <= targetDepth) {
return member.getHierarchy().getNullMember();
}
level=levels[targetDepth];
}
 else {
level=levelCalc.evaluateLevel(evaluator);
}
if (level.getDepth() < member.getLevel().getDepth()) {
return member.getHierarchy().getNullMember();
}
if (level == member.getLevel()) {
return member;
}
return getDescendant(evaluator.getSchemaReader(),member,level,opening);
}
}
;
}