public static <T> ImmutableList<T> load(
      Class<? extends T> service, ClassLoader loader, Optional<Pattern> allowedMissingClasses) {
    String resourceName = "META-INF/services/" + service.getName();
    List<URL> resourceUrls;
    try {
      resourceUrls = Collections.list(loader.getResources(resourceName));
    } catch (IOException e) {
      throw new ServiceConfigurationError("Could not look up " + resourceName, e);
    }
    ImmutableSet.Builder<Class<? extends T>> providerClasses = ImmutableSet.builder();
    for (URL resourceUrl : resourceUrls) {
      try {
        providerClasses.addAll(
            providerClassesFromUrl(resourceUrl, service, loader, allowedMissingClasses));
      } catch (IOException e) {
        throw new ServiceConfigurationError("Could not read " + resourceUrl, e);
      }
    }
    ImmutableList.Builder<T> providers = ImmutableList.builder();
    for (Class<? extends T> providerClass : providerClasses.build()) {
      try {
        T provider = providerClass.getConstructor().newInstance();
        providers.add(provider);
      } catch (ReflectiveOperationException e) {
        throw new ServiceConfigurationError("Could not construct " + providerClass.getName(), e);
      }
    }
    return providers.build();
  }
A replacement for {@link java.util.ServiceLoader} that avoids certain long-standing bugs. This
simpler implementation does not bother with lazy loading but returns all the service
implementations in one list. It makes sure that {@link URLConnection#setUseCaches} is called to
turn off jar caching, since that tends to lead to problems in versions before JDK 9.

@see <a href="https://github.com/google/auto/issues/718">Issue #718</a>
@see <a href="https://bugs.openjdk.java.net/browse/JDK-8156014">JDK-8156014</a>
value/src/main/java/com/google/auto/value/processor/SimpleServiceLoader.java