Skip to content

Commit

Permalink
Use java.util.function.Supplier instead of directly initializing LOGG…
Browse files Browse the repository at this point in the history
…ER (#6692)

The problem with the current implementation is that in Grails® framework applicatio (version 5.1.1), the compilation fails because the class `SoftServiceLoader` will try to initialize LOGGER during compilation and result in `MultipleCompilationErrorsException`. Please check grails/grails-core#12291 for more information. In this commit, we are using `java.util.function.Supplier` instead of directly initializing the LOGGER which will make sure it is initialized after compilation.

Fixes #6691 and so grails/grails-core#12291
  • Loading branch information
puneetbehl authored Jan 3, 2022
1 parent 9b83a90 commit 8866739
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.optim.StaticOptimizations;
import io.micronaut.core.reflect.ClassUtils;
import io.micronaut.core.util.SupplierUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -62,7 +63,7 @@
public final class SoftServiceLoader<S> implements Iterable<ServiceDefinition<S>> {
public static final String META_INF_SERVICES = "META-INF/services";

private static final Logger LOGGER = LoggerFactory.getLogger(SoftServiceLoader.class);
private static final Supplier<Logger> LOGGER = SupplierUtil.memoized(() -> LoggerFactory.getLogger(SoftServiceLoader.class));

private static final Map<String, SoftServiceLoader.StaticServiceLoader<?>> STATIC_SERVICES =
StaticOptimizations.get(Optimizations.class)
Expand Down Expand Up @@ -160,7 +161,7 @@ private static void measure(String label, Runnable op) {
op.run();
} finally {
long dur = System.nanoTime() - sd;
LOGGER.debug(label + " took " + TimeUnit.MILLISECONDS.convert(dur, TimeUnit.NANOSECONDS) + "ms");
LOGGER.get().debug(label + " took " + TimeUnit.MILLISECONDS.convert(dur, TimeUnit.NANOSECONDS) + "ms");
}
}

Expand All @@ -180,7 +181,7 @@ public void collectAll(@NonNull Collection<S> values, @Nullable Predicate<S> pre
} else {
collectDynamicServices(values, predicate, name);
}
LOGGER.debug("Loaded {} services of type {}", values.size(), name);
LOGGER.get().debug("Loaded {} services of type {}", values.size(), name);
});
}

Expand Down

0 comments on commit 8866739

Please sign in to comment.