qos-ch / logback

The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
Other
2.98k stars 1.28k forks source link

IllegalAccessException when creating thread factory #779

Closed jpmsilva closed 6 months ago

jpmsilva commented 7 months ago

We always run our application with JDK21 and -Dsun.reflect.debugModuleAccessChecks=true to check for possible issues resulting from module boundary issues. After recently upgrading logback, we started seeing this exception being logged:

java.lang.IllegalAccessException: class ch.qos.logback.core.util.ExecutorServiceUtil$1 cannot access a member of class java.lang.ThreadBuilders$VirtualThreadBuilder (in module java.base) with modifiers "public"
    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.Method.invoke(Method.java:571)
    at ch.qos.logback.core.util.ExecutorServiceUtil$1.makeThreadFactory(ExecutorServiceUtil.java:58)
    at ch.qos.logback.core.util.ExecutorServiceUtil$1.<init>(ExecutorServiceUtil.java:45)
    at ch.qos.logback.core.util.ExecutorServiceUtil.<clinit>(ExecutorServiceUtil.java:40)
    at ch.qos.logback.core.ContextBase.stopExecutorServices(ContextBase.java:247)
    at ch.qos.logback.core.ContextBase.stop(ContextBase.java:172)
    at ch.qos.logback.classic.LoggerContext.stop(LoggerContext.java:346)
[...snip...]

Now, while the class ExecutorServiceUtil catches that exception and handles it, it also points to an underlying issue: the getMethod(FACTORY_METHOD_NAME) is performed on the wrong (concrete) class java.lang.ThreadBuilders.VirtualThreadBuilder, instead of the public interface java.lang.Thread.Builder.

As such, I can't see any way the current code would work as is.

I hope to provide a PR to fix this shortly.

mkurz commented 6 months ago

I think this can be closed now? It's part of the 1.5 release

ceki commented 6 months ago

@mkurz Thank you for following up.

jpmsilva commented 6 months ago

Apologies for the spam in advance. I just wanted to confirm that the fix does indeed work, and we no longer observe the illegal access exception when starting the application with version 1.5. I also wanted to leave a word of thanks for the wonderful libraries that you provide to the community, and the amazing support and maintenance to them. I really enjoyed learning from the multijar release commit you provided, as I had never seen it actually done in a project. Thank you!