@SuppressWarnings({"unchecked", "rawtypes"})
  private void mergeFromField(
      final Map.Entry<FieldDescriptorType, Object> entry) {
    final FieldDescriptorType descriptor = entry.getKey();
    Object otherValue = entry.getValue();
    if (otherValue instanceof LazyField) {
      otherValue = ((LazyField) otherValue).getValue();
    }

    if (descriptor.isRepeated()) {
      Object value = getField(descriptor);
      if (value == null) {
        // Our list is empty, but we still need to make a defensive copy of
        // the other list since we don't know if the other FieldSet is still
        // mutable.
        fields.put(descriptor, new ArrayList((List) otherValue));
      } else {
        // Concatenate the lists.
        ((List) value).addAll((List) otherValue);
      }
    } else if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) {
      Object value = getField(descriptor);
      if (value == null) {
        fields.put(descriptor, otherValue);
      } else {
        // Merge the messages.
        fields.put(
            descriptor,
            descriptor.internalMergeFrom(
                ((MessageLite) value).toBuilder(), (MessageLite) otherValue)
            .build());
      }
    } else {
      fields.put(descriptor, otherValue);
    }
  }