Because the specified ThreadLocal variable is empty. You need to either set the value or specify the initial value.
ThreadLocal<String> threadLocal = ThreadLocal.withInitial(() -> "initial value");
or
ThreadLocal<String> threadLocal = new ThreadLocal<>();
threadLocal.set("value");
If you have not set a value, ThreadLocal defaults to null.
source
share