Skip to content

Commit

Permalink
Duplicate provider is just a warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed Oct 7, 2024
1 parent 12ebe80 commit a31fb9c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions std-bits/base/src/main/java/org/enso/base/lookup/Lookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import java.util.List;
import java.util.ServiceLoader;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;

public final class Lookup<T> implements Iterable<T> {
private final Function<ModuleLayer, ServiceLoader<T>> factory;
private List<ServiceLoader.Provider<T>> found;
private static final Logger logger = Logger.getLogger(Lookup.class.getName());

private Lookup(Function<ModuleLayer, ServiceLoader<T>> factory) {
this.factory = factory;
Expand Down Expand Up @@ -43,16 +46,12 @@ private List<ServiceLoader.Provider<T>> findAll() {
(p) -> {
if (serviceProviders.containsKey(p)) {
var prevLayer = serviceProviders.get(p);
throw new IllegalStateException(
"Error: Duplicate provider found: "
+ providerToString(p)
+ ". "
+ "Previous provider in layer '"
+ prevLayer
+ "'. "
+ "Current provider in layer '"
+ layer
+ "'.");
logger.log(
Level.WARNING,
String.format(
"Duplicate provider found: %s. Previous provider in layer '%s'."
+ " Current provider in layer '%s'.",
providerToString(p), prevLayer, layer));
}
serviceProviders.put(p, layer);
});
Expand Down

0 comments on commit a31fb9c

Please sign in to comment.