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

IllegalAccessException when creating thread factory #779

Closed
jpmsilva opened this issue Feb 5, 2024 · 3 comments
Closed

IllegalAccessException when creating thread factory #779

jpmsilva opened this issue Feb 5, 2024 · 3 comments
Assignees
Milestone

Comments

@jpmsilva
Copy link

jpmsilva commented Feb 5, 2024

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.

jpmsilva added a commit to jpmsilva/logback that referenced this issue Feb 5, 2024
jpmsilva added a commit to jpmsilva/logback that referenced this issue Feb 16, 2024
@ceki ceki added this to the 1.5.0 milestone Feb 16, 2024
@ceki ceki self-assigned this Feb 16, 2024
@mkurz
Copy link
Contributor

mkurz commented Feb 26, 2024

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

@ceki ceki closed this as completed Feb 26, 2024
@ceki
Copy link
Member

ceki commented Feb 26, 2024

@mkurz Thank you for following up.

@jpmsilva
Copy link
Author

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!

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

No branches or pull requests

3 participants