Program: 51071
Project: 51071
Buggy source:
/** 
 * Compiles an expression to a calc of the required result type. <p>Since the result of evaluating the calc will be passed to the method using reflection, it is important that the calc returns <em>precisely</em> the correct type: if a method requires an <code>int</code>, you can pass an   {@link Integer} but not a {@link Long}or   {@link Float}. <p>If it can be determined that the underlying calc will never return null, generates an optimal form with one fewer object instantiation.
 * @param compiler Compiler
 * @param exp Expression to compile
 * @param clazz Desired class
 * @return compiled expression
 */
private static Calc compileTo(ExpCompiler compiler,Exp exp,Class clazz){
  if (clazz == String.class) {
    return compiler.compileString(exp);
  }
 else   if (clazz == Date.class) {
    return compiler.compileDateTime(exp);
  }
 else   if (clazz == boolean.class) {
    return compiler.compileBoolean(exp);
  }
 else   if (clazz == byte.class) {
    final IntegerCalc integerCalc=compiler.compileInteger(exp);
    if (integerCalc.getResultStyle() == ResultStyle.VALUE_NOT_NULL) {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          return (byte)integerCalc.evaluateInteger(evaluator);
        }
      }
;
    }
 else {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          Integer i=(Integer)integerCalc.evaluate(evaluator);
          return i == null ? null : (byte)i.intValue();
        }
      }
;
    }
  }
 else   if (clazz == char.class) {
    final IntegerCalc integerCalc=compiler.compileInteger(exp);
    if (integerCalc.getResultStyle() == ResultStyle.VALUE_NOT_NULL) {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          return (char)integerCalc.evaluateInteger(evaluator);
        }
      }
;
    }
 else {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          Integer i=(Integer)integerCalc.evaluate(evaluator);
          return i == null ? null : (char)i.intValue();
        }
      }
;
    }
  }
 else   if (clazz == short.class) {
    final IntegerCalc integerCalc=compiler.compileInteger(exp);
    if (integerCalc.getResultStyle() == ResultStyle.VALUE_NOT_NULL) {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          return (short)integerCalc.evaluateInteger(evaluator);
        }
      }
;
    }
 else {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          Integer i=(Integer)integerCalc.evaluate(evaluator);
          return i == null ? null : (short)i.intValue();
        }
      }
;
    }
  }
 else   if (clazz == int.class) {
    return compiler.compileInteger(exp);
  }
 else   if (clazz == long.class) {
    final IntegerCalc integerCalc=compiler.compileInteger(exp);
    if (integerCalc.getResultStyle() == ResultStyle.VALUE_NOT_NULL) {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          return (long)integerCalc.evaluateInteger(evaluator);
        }
      }
;
    }
 else {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          Integer i=(Integer)integerCalc.evaluate(evaluator);
          return i == null ? null : (long)i.intValue();
        }
      }
;
    }
  }
 else   if (clazz == float.class) {
    final DoubleCalc doubleCalc=compiler.compileDouble(exp);
    if (doubleCalc.getResultStyle() == ResultStyle.VALUE_NOT_NULL) {
      return new AbstractCalc2(exp,doubleCalc){
        public Object evaluate(        Evaluator evaluator){
          Double v=(Double)doubleCalc.evaluate(evaluator);
          return v == null ? null : v.floatValue();
        }
      }
;
    }
 else {
      return new AbstractCalc2(exp,doubleCalc){
        public Object evaluate(        Evaluator evaluator){
          return (float)doubleCalc.evaluateDouble(evaluator);
        }
      }
;
    }
  }
 else   if (clazz == double.class) {
    return compiler.compileDouble(exp);
  }
 else   if (clazz == Object.class) {
    return compiler.compileScalar(exp,false);
  }
 else {
    throw newInternal("String_Node_Str" + clazz);
  }
}

Fixed version (ground truth):
/** 
 * Compiles an expression to a calc of the required result type. <p>Since the result of evaluating the calc will be passed to the method using reflection, it is important that the calc returns <em>precisely</em> the correct type: if a method requires an <code>int</code>, you can pass an   {@link Integer} but not a {@link Long}or   {@link Float}. <p>If it can be determined that the underlying calc will never return null, generates an optimal form with one fewer object instantiation.
 * @param compiler Compiler
 * @param exp Expression to compile
 * @param clazz Desired class
 * @return compiled expression
 */
private static Calc compileTo(ExpCompiler compiler,Exp exp,Class clazz){
  if (clazz == String.class) {
    return compiler.compileString(exp);
  }
 else   if (clazz == Date.class) {
    return compiler.compileDateTime(exp);
  }
 else   if (clazz == boolean.class) {
    return compiler.compileBoolean(exp);
  }
 else   if (clazz == byte.class) {
    final IntegerCalc integerCalc=compiler.compileInteger(exp);
    if (integerCalc.getResultStyle() == ResultStyle.VALUE_NOT_NULL) {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          return (byte)integerCalc.evaluateInteger(evaluator);
        }
      }
;
    }
 else {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          Integer i=(Integer)integerCalc.evaluate(evaluator);
          return i == null ? null : (byte)i.intValue();
        }
      }
;
    }
  }
 else   if (clazz == char.class) {
    final StringCalc stringCalc=compiler.compileString(exp);
    return new AbstractCalc2(exp,stringCalc){
      public Object evaluate(      Evaluator evaluator){
        final String string=stringCalc.evaluateString(evaluator);
        return Character.valueOf(string == null || string.length() < 1 ? (char)0 : string.charAt(0));
      }
    }
;
  }
 else   if (clazz == short.class) {
    final IntegerCalc integerCalc=compiler.compileInteger(exp);
    if (integerCalc.getResultStyle() == ResultStyle.VALUE_NOT_NULL) {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          return (short)integerCalc.evaluateInteger(evaluator);
        }
      }
;
    }
 else {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          Integer i=(Integer)integerCalc.evaluate(evaluator);
          return i == null ? null : (short)i.intValue();
        }
      }
;
    }
  }
 else   if (clazz == int.class) {
    return compiler.compileInteger(exp);
  }
 else   if (clazz == long.class) {
    final IntegerCalc integerCalc=compiler.compileInteger(exp);
    if (integerCalc.getResultStyle() == ResultStyle.VALUE_NOT_NULL) {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          return (long)integerCalc.evaluateInteger(evaluator);
        }
      }
;
    }
 else {
      return new AbstractCalc2(exp,integerCalc){
        public Object evaluate(        Evaluator evaluator){
          Integer i=(Integer)integerCalc.evaluate(evaluator);
          return i == null ? null : (long)i.intValue();
        }
      }
;
    }
  }
 else   if (clazz == float.class) {
    final DoubleCalc doubleCalc=compiler.compileDouble(exp);
    if (doubleCalc.getResultStyle() == ResultStyle.VALUE_NOT_NULL) {
      return new AbstractCalc2(exp,doubleCalc){
        public Object evaluate(        Evaluator evaluator){
          Double v=(Double)doubleCalc.evaluate(evaluator);
          return v == null ? null : v.floatValue();
        }
      }
;
    }
 else {
      return new AbstractCalc2(exp,doubleCalc){
        public Object evaluate(        Evaluator evaluator){
          return (float)doubleCalc.evaluateDouble(evaluator);
        }
      }
;
    }
  }
 else   if (clazz == double.class) {
    return compiler.compileDouble(exp);
  }
 else   if (clazz == Object.class) {
    return compiler.compileScalar(exp,false);
  }
 else {
    throw newInternal("String_Node_Str" + clazz);
  }
}