Program: 51483
Project: 51483
Buggy source:
public Calc compileCall(ResolvedFunCall call,ExpCompiler compiler){
  final MemberCalc memberCalc=compiler.compileMember(call.getArg(0));
  int flag=Flags.SELF;
  if (call.getArgCount() == 1) {
    flag=Flags.SELF_BEFORE_AFTER;
  }
  final boolean depthSpecified;
  if (call.getArgCount() >= 2) {
    depthSpecified=call.getArg(1).getType() instanceof NumericType;
  }
 else {
    depthSpecified=false;
  }
  if (call.getArgCount() >= 3) {
    flag=FunUtil.getLiteralArg(call,2,Flags.SELF,Flags.instance);
  }
  final boolean self=FunUtil.checkFlag(flag,Flags.SELF,true);
  final boolean before=FunUtil.checkFlag(flag,Flags.BEFORE,true);
  final boolean after=FunUtil.checkFlag(flag,Flags.AFTER,true);
  final boolean leaves=FunUtil.checkFlag(flag,Flags.LEAVES,true);
  if (depthSpecified && leaves) {
    final IntegerCalc depthCalc=call.getArgCount() > 1 ? compiler.compileInteger(call.getArg(1)) : null;
    return new AbstractListCalc(call,new Calc[]{memberCalc,depthCalc}){
      public List evaluateList(      Evaluator evaluator){
        final Member member=memberCalc.evaluateMember(evaluator);
        List result=new ArrayList();
        int depth=depthCalc.evaluateInteger(evaluator);
        final SchemaReader schemaReader=evaluator.getSchemaReader();
        if (depth < 0) {
          depth=Integer.MAX_VALUE;
        }
        descendantsLeavesByDepth(member,result,schemaReader,depth);
        hierarchize(result,false);
        return result;
      }
    }
;
  }
 else   if (depthSpecified) {
    final IntegerCalc depthCalc=call.getArgCount() > 1 ? compiler.compileInteger(call.getArg(1)) : null;
    return new AbstractListCalc(call,new Calc[]{memberCalc,depthCalc}){
      public List evaluateList(      Evaluator evaluator){
        final Member member=memberCalc.evaluateMember(evaluator);
        List result=new ArrayList();
        final int depth=depthCalc.evaluateInteger(evaluator);
        final SchemaReader schemaReader=evaluator.getSchemaReader();
        descendantsByDepth(member,result,schemaReader,depth,before,self,after,evaluator);
        hierarchize(result,false);
        return result;
      }
    }
;
  }
 else {
    final LevelCalc levelCalc=call.getArgCount() > 1 ? compiler.compileLevel(call.getArg(1)) : null;
    return new AbstractListCalc(call,new Calc[]{memberCalc,levelCalc}){
      public List evaluateList(      Evaluator evaluator){
        final Evaluator context=evaluator.isNonEmpty() ? evaluator : null;
        final Member member=memberCalc.evaluateMember(evaluator);
        List result=new ArrayList();
        final SchemaReader schemaReader=evaluator.getSchemaReader();
        final Level level=levelCalc != null ? levelCalc.evaluateLevel(evaluator) : member.getLevel();
        descendantsByLevel(schemaReader,member,level,result,before,self,after,leaves,context);
        hierarchize(result,false);
        return result;
      }
    }
;
  }
}

Fixed version (ground truth):
public Calc compileCall(ResolvedFunCall call,ExpCompiler compiler){
  final MemberCalc memberCalc=compiler.compileMember(call.getArg(0));
  int flag=Flags.SELF;
  if (call.getArgCount() == 1) {
    flag=Flags.SELF_BEFORE_AFTER;
  }
  final boolean depthSpecified;
  if (call.getArgCount() >= 2) {
    depthSpecified=call.getArg(1).getType() instanceof NumericType;
  }
 else {
    depthSpecified=false;
  }
  if (call.getArgCount() >= 3) {
    flag=FunUtil.getLiteralArg(call,2,Flags.SELF,Flags.instance);
  }
  final boolean self=FunUtil.checkFlag(flag,Flags.SELF,true);
  final boolean before=FunUtil.checkFlag(flag,Flags.BEFORE,true);
  final boolean after=FunUtil.checkFlag(flag,Flags.AFTER,true);
  final boolean leaves=FunUtil.checkFlag(flag,Flags.LEAVES,true);
  if (depthSpecified && leaves) {
    final IntegerCalc depthCalc=call.getArgCount() > 1 ? compiler.compileInteger(call.getArg(1)) : null;
    return new AbstractListCalc(call,new Calc[]{memberCalc,depthCalc}){
      public List evaluateList(      Evaluator evaluator){
        final Member member=memberCalc.evaluateMember(evaluator);
        List result=new ArrayList();
        int depth=depthCalc.evaluateInteger(evaluator);
        if (depth < 0) {
          depth=-1;
        }
        final SchemaReader schemaReader=evaluator.getSchemaReader();
        descendantsLeavesByDepth(member,result,schemaReader,depth);
        hierarchize(result,false);
        return result;
      }
    }
;
  }
 else   if (depthSpecified) {
    final IntegerCalc depthCalc=call.getArgCount() > 1 ? compiler.compileInteger(call.getArg(1)) : null;
    return new AbstractListCalc(call,new Calc[]{memberCalc,depthCalc}){
      public List evaluateList(      Evaluator evaluator){
        final Member member=memberCalc.evaluateMember(evaluator);
        List result=new ArrayList();
        final int depth=depthCalc.evaluateInteger(evaluator);
        final SchemaReader schemaReader=evaluator.getSchemaReader();
        descendantsByDepth(member,result,schemaReader,depth,before,self,after,evaluator);
        hierarchize(result,false);
        return result;
      }
    }
;
  }
 else {
    final LevelCalc levelCalc=call.getArgCount() > 1 ? compiler.compileLevel(call.getArg(1)) : null;
    return new AbstractListCalc(call,new Calc[]{memberCalc,levelCalc}){
      public List evaluateList(      Evaluator evaluator){
        final Evaluator context=evaluator.isNonEmpty() ? evaluator : null;
        final Member member=memberCalc.evaluateMember(evaluator);
        List result=new ArrayList();
        final SchemaReader schemaReader=evaluator.getSchemaReader();
        final Level level=levelCalc != null ? levelCalc.evaluateLevel(evaluator) : member.getLevel();
        descendantsByLevel(schemaReader,member,level,result,before,self,after,leaves,context);
        hierarchize(result,false);
        return result;
      }
    }
;
  }
}