`Thread.currentThread().getContextClassLoader()` is null
See original GitHub issueWay to reproduce
Just get ClassLoader in Handler
public class HelloServiceHandler implements HelloService.Iface {
@Override
public String sayHi(String name) throws TException {
// classLoader is null
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
return "Hi," + name;
}
}
Impact
Some third library required Thread.currentThread().getContextClassLoader() to get classloader, this will cause error in service.
Reason
When create Thread, contextClassLoader will get from parent thread, but currently the parent thread is netty thread, there’s no contextClassLoader.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Thread.getContextClassLoader() == null? - java - Stack Overflow
Java threads created from JNI code in a non-java thread have null ... Also in such context Thread.currentThread() returns null.
Read more >Thread.currentThread().getContextClassLoader() returns null ...
This returns null in the Windows image, but in the linux and MacOS images it returns a non-null object. The specific line where...
Read more >63612 – PooledConnection#connectUsingDriver, Thread ...
1. If "Thread.currentThread().getContextClassLoader()" is null, it essentially means that this thread is not associated with a web application.
Read more >Example usage for java.lang Thread getContextClassLoader
In this page you can find the example usage for java.lang Thread getContextClassLoader. Prototype. @CallerSensitive public ClassLoader getContextClassLoader().
Read more >java.lang.Thread.getContextClassLoader java code examples
invoker, Invocation invocation) throws RpcException { ClassLoader ocl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Are you using Kotlin coroutines with Armeria’s annotated service or gRPC-Kotlin? We may inject a custom coroutine context to push and pop a
ContextClassLoader. For example:As a workaround, you can do this:
Please let me know if this solves your problem.