Program: 104907
Project: 104907
Buggy source:
/** 
 * Converts known types from mongodb -> java.
 */
protected static Object objectFromValue(Class javaType,Object val){
  if (val == null)   return null;
  if (javaType == null)   return val;
  if (javaType == String.class) {
    return val.toString();
  }
 else   if (javaType == Character.class || javaType == char.class) {
    return val.toString().charAt(0);
  }
 else   if (javaType == Integer.class || javaType == int.class) {
    return ((Number)val).intValue();
  }
 else   if (javaType == Long.class || javaType == long.class) {
    return ((Number)val).longValue();
  }
 else   if (javaType == Byte.class || javaType == byte.class) {
    Object dbValue=val;
    if (dbValue instanceof Byte)     return dbValue;
 else     if (dbValue instanceof Double)     return ((Double)dbValue).byteValue();
 else     if (dbValue instanceof Integer)     return ((Integer)dbValue).byteValue();
    String sVal=val.toString();
    return Byte.parseByte(sVal);
  }
 else   if (javaType == Short.class || javaType == short.class) {
    Object dbValue=val;
    if (dbValue instanceof Short)     return dbValue;
 else     if (dbValue instanceof Double)     return ((Double)dbValue).shortValue();
 else     if (dbValue instanceof Integer)     return ((Integer)dbValue).shortValue();
    String sVal=val.toString();
    return Short.parseShort(sVal);
  }
 else   if (javaType == Float.class || javaType == float.class) {
    Object dbValue=val;
    if (dbValue instanceof Double)     return ((Double)dbValue).floatValue();
    String sVal=val.toString();
    return Float.parseFloat(sVal);
  }
 else   if (javaType == Locale.class) {
    return parseLocale(val.toString());
  }
 else   if (javaType.isEnum()) {
    return Enum.valueOf(javaType,val.toString());
  }
 else   if (javaType == Key.class) {
    return new Key((DBRef)val);
  }
  return val;
}

Fixed version (ground truth):
/** 
 * Converts known types from mongodb -> java.
 */
protected static Object objectFromValue(Class javaType,Object val){
  if (val == null)   return null;
  if (javaType == null)   return val;
  if (javaType == String.class) {
    return val.toString();
  }
 else   if (javaType == Character.class || javaType == char.class) {
    return val.toString().charAt(0);
  }
 else   if (javaType == Integer.class || javaType == int.class) {
    if (val instanceof String) {
      return Integer.parseInt((String)val);
    }
 else {
      return ((Number)val).intValue();
    }
  }
 else   if (javaType == Long.class || javaType == long.class) {
    if (val instanceof String) {
      return Long.parseLong((String)val);
    }
 else {
      return ((Number)val).longValue();
    }
  }
 else   if (javaType == Byte.class || javaType == byte.class) {
    Object dbValue=val;
    if (dbValue instanceof Byte)     return dbValue;
 else     if (dbValue instanceof Double)     return ((Double)dbValue).byteValue();
 else     if (dbValue instanceof Integer)     return ((Integer)dbValue).byteValue();
    String sVal=val.toString();
    return Byte.parseByte(sVal);
  }
 else   if (javaType == Short.class || javaType == short.class) {
    Object dbValue=val;
    if (dbValue instanceof Short)     return dbValue;
 else     if (dbValue instanceof Double)     return ((Double)dbValue).shortValue();
 else     if (dbValue instanceof Integer)     return ((Integer)dbValue).shortValue();
    String sVal=val.toString();
    return Short.parseShort(sVal);
  }
 else   if (javaType == Float.class || javaType == float.class) {
    Object dbValue=val;
    if (dbValue instanceof Double)     return ((Double)dbValue).floatValue();
    String sVal=val.toString();
    return Float.parseFloat(sVal);
  }
 else   if (javaType == Locale.class) {
    return parseLocale(val.toString());
  }
 else   if (javaType.isEnum()) {
    return Enum.valueOf(javaType,val.toString());
  }
 else   if (javaType == Key.class) {
    return new Key((DBRef)val);
  }
  return val;
}