code: public int getRepeatedFieldCount(final FieldDescriptorType descriptor) {
      if (!descriptor.isRepeated()) {
        throw new IllegalArgumentException(
          "getRepeatedField() can only be called on repeated fields.");
      }
  
      final Object value = getField(descriptor);
      if (value == null) {
        return 0;
      } else {
        return ((List<?>) value).size();
      }
    }
docs: Useful for implementing
  {@link Message#getRepeatedFieldCount(Descriptors.FieldDescriptor)}.