Program: 7338
Project: 7338
Buggy source:
/** 
 * Translate a field that fits a   {@link Schema} field into a type that Hive understands.For example, a ByteBuffer is allowed by schema but Hive only understands byte arrays, so all ByteBuffers must be changed into byte arrays. Reflection is used to examine java objects if the expected hive type is a struct.
 * @param field value of the field to deserialize.
 * @param typeInfo type of the field as expected by Hive.
 * @param schema schema of the field.
 * @return translated field.
 * @throws NoSuchFieldException if a struct field was expected but not found in the object.
 * @throws IllegalAccessException if a struct field was not accessible.
 */
private Object deserializeField(Object field,TypeInfo typeInfo,Schema schema) throws NoSuchFieldException, IllegalAccessException {
  boolean isNullable=schema.isNullable();
  if (field == null) {
    if (isNullable) {
      return null;
    }
 else {
      throw new UnexpectedFormatException("String_Node_Str");
    }
  }
  if (isNullable) {
    schema=schema.getNonNullable();
  }
switch (typeInfo.getCategory()) {
case PRIMITIVE:
    return deserializePrimitive(field,(PrimitiveTypeInfo)typeInfo);
case LIST:
  return deserializeList(field,(ListTypeInfo)typeInfo,schema.getComponentSchema());
case MAP:
return deserializeMap(field,(MapTypeInfo)typeInfo,schema.getMapSchema());
case STRUCT:
StructTypeInfo structTypeInfo=(StructTypeInfo)typeInfo;
ArrayList<String> innerFieldNames=structTypeInfo.getAllStructFieldNames();
ArrayList<TypeInfo> innerFieldTypes=structTypeInfo.getAllStructFieldTypeInfos();
return flattenRecord(field,innerFieldNames,innerFieldTypes,schema);
case UNION:
return field;
}
return null;
}

Fixed version (ground truth):
/** 
 * Translate a field that fits a   {@link Schema} field into a type that Hive understands.For example, a ByteBuffer is allowed by schema but Hive only understands byte arrays, so all ByteBuffers must be changed into byte arrays. Reflection is used to examine java objects if the expected hive type is a struct.
 * @param field value of the field to deserialize.
 * @param typeInfo type of the field as expected by Hive.
 * @param schema schema of the field.
 * @return translated field.
 * @throws NoSuchFieldException if a struct field was expected but not found in the object.
 * @throws IllegalAccessException if a struct field was not accessible.
 */
private Object deserializeField(Object field,TypeInfo typeInfo,Schema schema) throws NoSuchFieldException, IllegalAccessException {
  boolean isNullable=schema.isNullable();
  if (field == null) {
    if (isNullable) {
      return null;
    }
 else {
      throw new UnexpectedFormatException("String_Node_Str");
    }
  }
  if (isNullable) {
    schema=schema.getNonNullable();
  }
switch (typeInfo.getCategory()) {
case PRIMITIVE:
    return deserializePrimitive(field,(PrimitiveTypeInfo)typeInfo);
case LIST:
  ListTypeInfo listTypeInfo=(ListTypeInfo)typeInfo;
if (isByteArray(listTypeInfo) && !(field instanceof Collection)) {
  return deserializeByteArray(field);
}
return deserializeList(field,(ListTypeInfo)typeInfo,schema.getComponentSchema());
case MAP:
return deserializeMap(field,(MapTypeInfo)typeInfo,schema.getMapSchema());
case STRUCT:
StructTypeInfo structTypeInfo=(StructTypeInfo)typeInfo;
ArrayList<String> innerFieldNames=structTypeInfo.getAllStructFieldNames();
ArrayList<TypeInfo> innerFieldTypes=structTypeInfo.getAllStructFieldTypeInfos();
return flattenRecord(field,innerFieldNames,innerFieldTypes,schema);
case UNION:
return field;
}
return null;
}