Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit provider fails when used with module system #392

Open
rfscholte opened this issue Feb 3, 2024 · 4 comments · May be fixed by #393
Open

Explicit provider fails when used with module system #392

rfscholte opened this issue Feb 3, 2024 · 4 comments · May be fixed by #393

Comments

@rfscholte
Copy link

rfscholte commented Feb 3, 2024

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)
rfscholte added a commit to rfscholte/slf4j that referenced this issue Feb 4, 2024
rfscholte added a commit to rfscholte/slf4j that referenced this issue Feb 4, 2024
this fixes qos-ch#392

Signed-off-by: Robert Scholte <rfscholte@apache.org>
@ceki
Copy link
Member

ceki commented Feb 4, 2024

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
}

@rfscholte
Copy link
Author

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.

@ceki
Copy link
Member

ceki commented Feb 5, 2024

@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.

@rfscholte
Copy link
Author

solution confirmed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants