private static <T> ImmutableSet<Class<? extends T>> providerClassesFromUrl(
      URL resourceUrl,
      Class<? extends T> service,
      ClassLoader loader,
      Optional<Pattern> allowedMissingClasses)
      throws IOException {
    ImmutableSet.Builder<Class<? extends T>> providerClasses = ImmutableSet.builder();
    URLConnection urlConnection = resourceUrl.openConnection();
    urlConnection.setUseCaches(false);
    List<String> lines;
    try (InputStream in = urlConnection.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in, UTF_8))) {
      lines = reader.lines().collect(toList());
    }
    List<String> classNames =
        lines.stream()
            .map(SimpleServiceLoader::parseClassName)
            .flatMap(Streams::stream)
            .collect(toList());
    for (String className : classNames) {
      Class<?> c;
      try {
        c = Class.forName(className, false, loader);
      } catch (ClassNotFoundException e) {
        if (allowedMissingClasses.isPresent()
            && allowedMissingClasses.get().matcher(className).matches()) {
          continue;
        }
        throw new ServiceConfigurationError("Could not load " + className, e);
      }
      if (!service.isAssignableFrom(c)) {
        throw new ServiceConfigurationError(
            "Class " + className + " is not assignable to " + service.getName());
      }
      providerClasses.add(c.asSubclass(service));
    }
    return providerClasses.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