Explicit provider fails when used with module system
rfscholte opened this issue · 4 comments
it looks like it is trying to create e new instance based on this property. I guess it would be better to loop over the providers and check if there is a matching instance.
SLF4J(I): Attempting to load provider "org.slf4j.simple.SimpleServiceProvider" specified via "slf4j.provider" system property
SLF4J(E): Failed to instantiate the specified SLF4JServiceProvider (org.slf4j.simple.SimpleServiceProvider)
SLF4J(E): Reported exception:
java.lang.IllegalAccessException: class org.slf4j.LoggerFactory (in module org.slf4j) cannot access class org.slf4j.simple.SimpleServiceProvider (in module org.slf4j.simple) because module org.slf4j.simple does not export org.slf4j.simple to module org.slf4j
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:394)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:714)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:495)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
at org.slf4j@2.0.10/org.slf4j.LoggerFactory.loadExplicitlySpecified(LoggerFactory.java:225)
I suspect that following version of slf4j-simple/.../java9/module-info.java will solve the issue
module org.slf4j.simple {
requires org.slf4j;
exports org.slf4j.simple; // addition
provides org.slf4j.spi.SLF4JServiceProvider with org.slf4j.simple.SimpleServiceProvider;
opens org.slf4j.simple to org.slf4j; // addition
}
that will work, but that means that every ServiceProvider must do so. The provides
hands it over to the JRE, which has always access to the providers.
If you want to first initialize it based on the system property, you might not directly want to fail, but give it another try via the provider and check if there's a matching provider.
@rfscholte The rationale here is that if the provider is specified explicitly, it must be known to work.
Anyway, commit da91e4f should solve the problem. Please let me know if this solves the problem. I intend to cut a release shortly.
solution confirmed