code: public static ExtensionRegistry addToRegistry(final FieldDescriptor extension,
        final ExtensionRegistry registry) {
      if (extension.getJavaType() == JavaType.MESSAGE) {
        registry.add(extension, DynamicMessage.getDefaultInstance(extension.getMessageType()));
      } else {
        registry.add(extension);
      }
  
      return registry;
    }
docs: Adds extension to the registry, making a default DynamicMessage if its type is a Message.